我对SQL很新,所以请给我一些松懈(哈哈)。我尝试过以下脚本,但出于某种原因,它不起作用?我已经仔细检查了一切,这里的错误在哪里?
$conn = new mysqli('localhost','root','', 'hugh_network') or die("Error in the connect.." . mysqli_error($conn));
$sql = "INSERT INTO accounts (first, last, email, username, password, unid, grp)
VALUES ('$first', '$last', '$email', '$username', '$password', '$unid', '$grp')";
if ($conn->query($sql) === TRUE) {} else {
die("An error has occured in the database connection. Contact an admin or developer.");
}
$conn->close();
答案 0 :(得分:-1)
你的代码语法看起来很好,尝试将它包装在try / catch中以防万一我们错过了,并且首先逃避你的所有价值$ $ ....
try {
$conn = new mysqli('localhost','root','', 'hugh_network') or die("Error in the connect.." . mysqli_error($conn));
$sql = "INSERT INTO accounts (first, last, email, username, password, unid, grp) VALUES ('$first', '$last', '$email', '$username', '$password', '$unid', '$grp')";
if ($conn->query($sql) === TRUE) {
} else {
die("An error has occured in the database connection. Contact an admin or developer.");
}
$conn->close();
} catch (Exception $e) {
die($e->getMessage());
}
或检查数据库的完整性,列名,用户权限或类似内容......
取得联系;)