MySQL错误的语法,但没有第114行

问题描述 投票:0回答:2

我收到以下错误

您的SQL语法有误;检查手册对应于您的MySQL服务器版本以使用正确的语法在第114行的“附近”

但是我的代码只有27行

<?php
    $DB_NAME = 'QCSYSTEM';
    $DB_HOST = 'monitor';
    $DB_USER = 'QCSYSTEM';
    $DB_PASS = '247#Direct';
    $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
        if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    // A QUICK QUERY ON A FAKE USER TABLE
    $query = "SELECT username FROM `users` WHERE";
    $result = $mysqli->query($query) or die($mysqli->error.__LINE__);

    // GOING THROUGH THE DATA
    if($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            echo stripslashes($row['username']);    
        }
    }
    else {
        echo 'NO RESULTS';  
    }
// CLOSE CONNECTION
mysqli_close($mysqli);
?>
php mysql
2个回答
1
投票

您缺少在此处陈述您的WHERE子句

$query = "SELECT username FROM `users` WHERE";

要么删除它

$query = "SELECT username FROM `users`";

或应用任何条款

$query = "SELECT username FROM `users` WHERE column = 'something'";

1
投票
$query = "SELECT username FROM `users` WHERE";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

您未指定where子句,因此查询失败。

热门问题
推荐问题
最新问题