PHP:准备好的语句(新手)得到这个错误


PHP: Prepared statements (newbie) getting this error

我是一个准备语句的新手,并试图让一些简单的东西发挥作用。

这是我的数据库表:

`unblocker_users` (
  `uno` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_email` varchar(210) DEFAULT NULL,
  `pw_hash` varchar(30) DEFAULT NULL,
  `email_confirmed` tinyint(4) DEFAULT NULL,
  `total_requests` bigint(20) DEFAULT NULL,
  `today_date` date DEFAULT NULL,
  `accessed_today` tinyint(4) DEFAULT NULL,)

这是我插入一些测试数据的功能

function add_new_user($e_mail1)
    {
    require_once "db.php";
// ####### Below line is giving an error ########
$stmt = $mysqli->prepare("INSERT INTO unblocker_users VALUES ("",?, ?,0,0,?,0)");
$stmt->bind_param('sss', $e_mail1, $this->genRandomString(1),$this->today_date()); 
$stmt->execute();
$stmt->close(); 
$done = $stmt->affected_rows;
return $done;
    }

正如你在上面看到的,我已经标记了一条给我带来错误的线。错误为" Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in..."

我哪里错了?

此行可能导致出现问题

$stmt = $mysqli->prepare("INSERT INTO unblocker_users VALUES ("",?, ?,0,0,?,0)");

看到你再次关闭和打开值中的字符串,将""更改为''这就是我快速浏览所能看到的。

你有一个双引号字符串。PHP认为

"INSERT INTO unblocker_users VALUES ("",?, ?,0,0,?,0)"

是2个字符串:

"INSERT INTO unblocker_users VALUES ("

",?, ?,0,0,?,0)"

但不是你想用它们做什么。

将外部引号改为单引号,它应该可以工作:

'INSERT INTO unblocker_users VALUES ("",?, ?,0,0,?,0)'

"INSERT INTO unblocker_users VALUES ("",?, ?,0,0,?,0)"

在php中,如果你想在双引号中使用双引号,你必须转义内部的

"INSERT INTO unblocker_users VALUES ('"'",?, ?,0,0,?,0)"

或者使用单引号作为外部。。。

'INSERT INTO unblocker_users VALUES ("",?, ?,0,0,?,0)'

或内部报价

"INSERT INTO unblocker_users VALUES ('',?, ?,0,0,?,0)"

据我所知,mySQL无论如何都使用单引号