我是mysql查询的新手,并且无法将此mysqli语句插入到mysql中。我的脚本设置或我的$ sql有什么问题吗? (我没有收到任何错误,它只是没有插入)
<?php
$login = "coolkidz"; //this line insets into username
$sname = "heyu";
$city = "beautiful";
$empass = "awesome";
$eusername = "what";
$mcode = "nice";
$sql = "INSERT INTO login(sname, city, empass, eusername, mcode, username) VALUES('$sname', '$city', '$empass', '$eusername', '$mcode', '$login')");
$hostname_Database = "censored";
$database_Database = "censored";
$username_Database = "censored";
$password_Database = "censored";
$mysqli = new mysqli($hostname_Database, $username_Database, $password_Database, $database_Database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$result = $mysqli->query($sql);
if (!$result) {
printf("%s\n", $mysqli->error);
exit();
}
?>
答案 0 :(得分:0)
你有这一行:
$sql = "INSERT INTO login(sname, city, empass, eusername, mcode, username) VALUES('$sname', '$city', '$empass', '$eusername', '$mcode', '$login')");
尝试将其更改为以下内容:
$sql = "INSERT INTO login(`sname`, `city`, `empass`, `eusername`, `mcode`, `username`) VALUES('$sname', '$city', '$empass', '$eusername', '$mcode', '$login')";
请注意列号中的`,
你在行尾有一个)
多
答案 1 :(得分:0)
Please update "..'$var'..." to "..'" . $var . "'..." like ex:
=>
$sql = "INSERT INTO login(sname, city, empass, eusername, mcode, username)
VALUES('" . $sname . "', '" . $city . "', '" . $empass . "', '"
. $eusername . "','" . $mcode . "', '" . $login . "')";