开发者

What is wrong with my mysql code?

What is wrong? I get a syntax error. This code was working a week before and I made no changes to it.开发者_StackOverflow

Trying the query itself in phpmyadmin gave me the syntax error, any help?


'$version', '0', '1',);
What's that comma doing there


You have a comma after the last value - is that intentional?


If you did not change the query at all and the comma issue others have pointed out is not the answer, then the inputs must have changed. Where are the values like $username and $password coming from? Are they properly escaped/sanitized? If the inputs are not escaped, and a particular value has a single-quote in it, then that would cause a syntax error (more importantly, it would also expose you to SQL injection).

If the values are not currently escaped, the best solution is to use mysql_real_escape_string() on each variable in the insert, or to use prepared statements.


Where is your code according to mr.robus code

    '$version', '0', '1',);

Yes He's Right We Can't Include comma in after last field


Not using prepared statements in your code is the error.

The safer and better way is to look at mysqli::prepare or pdo::prepare

$stmt = $mysqli->prepare("INSERT INTO `vewy`.`accountinfo` (`id`, `username`, `password`) VALUES (0, ?, ?)");
$stmt->bind_param('ss', $username, $password);
$username = 'admin';
$password = 'stackoverflow';
$stmt->execute();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜