Php 为什么我的数据不能插入?
我不知道我的代码有什么问题。它不会将数据插入数据库。给你Php 为什么我的数据不能插入?,php,mysql,database,insert,pdo,Php,Mysql,Database,Insert,Pdo,我不知道我的代码有什么问题。它不会将数据插入数据库。给你 $adduser = $con->prepare("INSERT INTO 'basicuserinfo'(email, password, firstname, lastname) VALUES(:email, :password, :firstname, :lastname)"); $adduser->bindValue(':email', $email); $adduser->bindValue('
$adduser = $con->prepare("INSERT INTO 'basicuserinfo'(email, password, firstname, lastname) VALUES(:email, :password, :firstname, :lastname)");
$adduser->bindValue(':email', $email);
$adduser->bindValue(':password', $password);
$adduser->bindValue(':firstname', $firstname);
$adduser->bindValue(':lastname', $lastname);
$adduser->execute();
插入“basicuserinfo”(电子邮件、密码、名字、姓氏)值(:email、:password、:firstname、:lastname)
这不是有效的SQL语句。摆脱
”
s.你确定它会成功吗?您没有按以下方式检查执行:
if(!$adduser->execute()) echo "Execute failed";
您可能会发现它在“环绕表名”上抛出了一个错误。试试这个
$adduser = $con->prepare("INSERT INTO `basicuserinfo`(email, password, firstname, lastname)
VALUES(?, ? , ? , ? )");
$adduser->bindParam('ssss', $email,$password , $firstname,$lastname);
$adduser->execute();
通过这种prepare语句的方式,您可以减少执行时间
然后不要把apostapy放在tablename前面按照描述的方式连接,然后找出答案哦,等等,这样更容易。从表名中删除
”
s。给自己买一本关于基本SQL的书syntax@YourCommonSense表名可能区分大小写,问题可能是“basicuserinfo”到“(”)之间缺少空格。其次,我建议将$adduser->bindValue(“:email”,“$email”);
更改为:$adduser->bindValue(“:email”,“$email,PDO::PARAM_STR);
并使用所有参数执行此操作此代码不应为空。正确的方法在标记wiki中描述。