当我尝试将数据插入MySQL时,会导致错误:
“已成功连接错误:INSERT INTO登录('nick,pass')VALUES (',')您的SQL语法中有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近''nick,pass')VALUES(',')'在第1行“
<?php
$servername = "mysql1.000webhost.com";
$username = "a5287585_login";
$password = "*****";
$dbname = "a5287585_login";
$nickname = $_POST['nick'];
$pass = $_POST['password'];
// Vytvorenie pripojenia - Creating connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully ";
// Vloženie dát (Nick,ecc..) - Data inserting
$sql = "INSERT INTO login (nick, pass)
VALUES ('$nick, $pass')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
感谢您的帮助。
答案 0 :(得分:1)
此行错误
$sql = "INSERT INTO login (nick, pass) VALUES ('$nick, $pass')";
应该是
$sql = "INSERT INTO login (nick, pass) VALUES ('$nickname', '$pass')";
^ ^// saperate quotes for both the values