[英]mysql insert PHP statement keeps throwing error
Does anybody know why the following PHP
code keeps throwing errors: I have been unable to log any proper error other than the if statement $result not going through and giving me the Echo 'Error'
statement. 有谁知道为什么下面的
PHP
代码不断抛出错误:除了if语句$ result没有通过并给我Echo 'Error'
语句以外,我无法记录任何适当的错误。 Is there something wrong with my insertion? 我的插入内容有问题吗?
$new_tbl_name = 'Password_Reset';
$sql = "INSERT INTO $new_tbl_name (Email, Key) VALUES ('$email','$resetHash')";
$result = mysql_query($sql);
if ($result) {
}
else {
echo 'Error';
}
key
is a reserved word , you'll have to escape it: key
是保留字 ,您必须对其进行转义:
INSERT INTO $new_tbl_name (Email, `Key`) VALUES
^ ^
As a general suggestion, simply saying "error" is utterly useless for debugging purposes. 作为一般建议,简单地说“错误”对于调试目的完全没有用。 Have mysql TELL you what's wrong:
有mysql告诉你怎么了:
if (!$result) {
die(mysql_error());
}
so you have a clue as to what's wrong, instead of just poking around in the dark. 这样您就可以知道发生了什么问题,而不仅仅是在黑暗中闲逛。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.