質問

This is my code. I know this should be easy, but somehow, SQL returns a parse error. Please Help.

$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD,DB_DATABASE);
if(mysqli_connect_errno()) {
    die('SQL ERROR : ' . mysqli_connect_error());
}
mysqli_autocommit($link, FALSE);

    $query = "INSERT INTO feedbackExit (1a, 2a, 3a, 4a, 5a, 1b, 2b, 3b, 4b, 5b, 6b, 1c, 2c, 3c, 4c, 5c, 6c, 1d, 2d, 3d, 4d, 5d, 6d, 1e, 2e) 
              VALUES (".$_POST['1a'].",".$_POST['2a'].",".$_POST['3a'].",".$_POST['4a'].",".$_POST['5a'].",
                      ".$_POST['1b'].",".$_POST['2b'].",".$_POST['3b'].",".$_POST['4b'].",".$_POST['5b'].",".$_POST['6b'].",
                      ".$_POST['1c'].",".$_POST['2c'].",".$_POST['3c'].",".$_POST['4c'].",".$_POST['5c'].",".$_POST['6c'].",
                      ".$_POST['1d'].",".$_POST['2d'].",".$_POST['3d'].",".$_POST['4d'].",".$_POST['5d'].",".$_POST['6d'].",
                      ".$_POST['1e'].",".$_POST['2e']")"; 
    $q1 = mysqli_query($link,$query);
    $query = "UPDATE ".$_SESSION['SESS_AUTH']." SET  `refExitHash` =  '".md5($_SESSION['SESS_USERNAME'], $raw_output = null)."'"."  WHERE  `index`='".$_SESSION['SESS_USERNAME']."'";
    $q2 = mysqli_query($link,$query);
    if (!($q1 and $q2) )
    {
     die('Error: ' . mysqli_errno($link));
     mysqli_rollback($link);
    }
    else 
    {
 header("location: FormExitPostSuccess.php");
 mysqli_commit($link);
    }
    mysqli_close($link); 

SQL throws the following parse error :
Parse error: syntax error, unexpected ')', expecting ',' or ';' in opt/lampp/htdocs/New/feedback/WebsiteRoot/FormExitPostSuccess.php on line 20

Line 20 in my code is : $q1 = mysqli_query($link,$query);

Edit: all valuse in array _POST are from radio buttons. Is validation still required??

役に立ちましたか?

解決

All the comments are correct in my opinion, so don't ignore them, but the error appears to be on the last line of your SQL:

".$_POST['1e'].",".$_POST['2e']")"; 

should be

".$_POST['1e'].",".$_POST['2e'] . ")"; 

(Note the addition of the dot towards the end.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top