我一直在尝试通过PHP代码将表单数据传递到数据库,但是它不起作用,我已经查看了代码的千分之一,因为可能的错误但是找不到一个作为初学者。表单实际上会提交,但没有任何内容可以访问数据库。
任何快速帮助都将深表感谢。这是代码:
$conn = @mysqli_connect('localhost', 'root', 'aboki');
if (mysqli_connect_error()) {
die('Connect Error: ' . mysqli_connect_error());
}
$qry = "INSERT INTO users (email, firstName, surname, userName, password, birthday) values ($email, $firstName, $surname, $userName, $password, $userDOB)";
$result = mysqli_query($conn, $qry);
答案 0 :(得分:1)
试试这个
$qry = "INSERT INTO users (email, firstName, surname, userName, password, birthday)
values ('$email', '$firstName', '$surname', '$userName', '$password', '$userDOB')";
答案 1 :(得分:1)
首先,您没有引用未插入的值...
这会解决它(但我强烈建议你不要使用这种方法!):
$qry = "INSERT INTO users (email, firstName, surname, userName, password, birthday) values ('$email', '$firstName', '$surname', '$userName', '$password', '$userDOB')";
最好充分利用mysqli
提供的预定义函数,并在准备好的语句中绑定这些参数,如下所示:
mysqli_prepare($conn,"INSERT INTO users (email, firstName, surname, userName, password, birthday) values (?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($conn, 'TYPES_HERE',$email, $firstName, $surname, $userName, $password, $birthday)
答案 2 :(得分:0)
我有数据插入解决方案,你可以尝试一下。
$conn= mysqli_connect("localhost", "root", "my_password", "world");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "INSERT INTO users
(email, firstName, surname, userName, password, birthday) VALUES
($email, $firstName, $surname, $userName, $password, $userDOB)";
mysqli_query($conn, $query);
printf ("New Record has id %d.\n", mysqli_insert_id($link));
mysqli_close($link);
正如你在查询中使用mysqli一样,语法完全不同,
随意提问。
由于
答案 3 :(得分:-6)
示例:
$stmt = mysqli_prepare($conn, "SELECT District FROM City WHERE Name=?")) {
$stmt->bind_param("s", $city);
$stmt->execute();