【发布时间】:2013-04-03 21:45:44
【问题描述】:
我已将我的注册脚本从 mysql 转换为 mysqli。我作为 mysql 工作得很好,但是现在它给了我错误
Commands out of sync; you can't run this command now
这是我用来注册用户的函数
function register_user($register_data) {
global $myConnection;
array_walk($register_data, 'array_sanitize');
//Make the array readable and seperate the fields from data
$fields = '`' . implode('`, `', array_keys($register_data)) . '`';
$data = '\'' . implode('\', \'', $register_data) . '\'';
//Insert the data and email an activation email to the user
mysqli_query($myConnection, "INSERT INTO `members` ($fields) VALUES ($data)") or die(mysqli_error($myConnection));
email($register_data['mem_email'], 'Activate your account', "Hello " . $register_data['mem_first_name'] . ",\n\nThank you for creating an account with H Fencing. Please use the link below to activate your account so we can confirm you identity:\n\nhttp://blah.blah.co.uk/activate.php?mem_email=" . $register_data['mem_email'] . "&email_code=" . $register_data['email_code'] . "\n\n - David & Jay ");
}
电子邮件发送正常,包含我阵列中的正确数据。但是没有数据插入到数据库中,我得到了上面提到的错误。我以前从未遇到过这个错误。
【问题讨论】:
-
1.在运行之前打印出查询并查看它。 2. 参数化您的查询。 3. 看在上帝的份上,参数化您的查询。