Skip to content
Advertisement

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: %sn", 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);
?>

Advertisement

Answer

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'";
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement