我有两个代码可以将数据放入数据库,但它会产生错误,请查看下面的代码。
$email = "example@hotmail.com"; //email
$pass = "helloworld"; //password
$fname = "Example"; //first name
$lname = "Man"; //last name
$birth = "2012-2-1"; //birthday
$gender = "male"; //gender
$site_prefix = "my_"; //table prefix
此代码不起作用并输出错误
$sql = "
INSERT INTO `{$site_prefix}login` (`email`,`pass`)
VALUES ('$email','$pass');
INSERT INTO `{$site_prefix}users` (`fname`,`lname`,`birthday`,`gender`)
VALUES ('$fname','$lname','$birth','$gender')";
mysql_query($sql,$con) or die(mysql_error());
错误
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以获取正确的语法,以便在第 2 行的 'INSERT INTO my_users ( fname
, lname
, birthday
, gender
) VALUES ('Example','Ma' 附近使用
此代码正常工作
$sql = "INSERT INTO `{$site_prefix}login` (`email`,`pass`) VALUES ('$email','$pass');";
$sql1 = "INSERT INTO `{$site_prefix}users` (`fname`,`lname`,`birthday`,`gender`) VALUES ('$fname','$lname','$birth','$gender')";
mysql_query($sql,$con) or die(mysql_error());
mysql_query($sql1,$con) or die(mysql_error());