简体   繁体   中英

MySQL wrong syntax but no line 114

I am getting the following error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 114

but my code is only 27 lines long

<?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);
?>
$query = "SELECT username FROM `users` WHERE";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

You have no where clause specified so the query is failing.

You are missing to state your WHERE clause here

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

Either remove it

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

or apply any clause

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM