Search code examples
mysqlsqlsyntaxmysql-error-1064

Head busting MYSQL error 1064 What's Wrong with my Syntax?


I've been staring at this for a moment and think I'm not perceiving the obvious.

The resulting display is 1064 (mysql reference says it's a syntax error)

$query = "INSERT INTO members ( id , username , password , all , articles ) VALUES ( ";
    $query .= "'' , " ;
    $query .= $username . "' , '" ;
    $query .= $password . "' , '" ;
    $query .= $allVals . "' , ";
    $query .= "'' );";
    $result = mysqli_query($con, $query);
    if (mysqli_errno($con)){
            echo mysqli_errno($con);
            echo mysqli_connect_error($con);
    }

I should note that $allVals is an encoded json object.

What's wrong with my query?


Solution

  • It looks like there is a single quote after $username, but not before:

    $query = "INSERT INTO members ( id , username , password , all , articles ) VALUES ( ";
        $query .= "'' , '" ; //missed the quote here
        $query .= $username . "' , '" ;
        $query .= $password . "' , '" ;
        $query .= $allVals . "' , ";
        $query .= "'' );";
        $result = mysqli_query($con, $query);
        if (mysqli_errno($con)){
                echo mysqli_errno($con);
                echo mysqli_connect_error($con);
        }