我看到有类似的问题,但似乎没有解决我的问题。
我注册了一位新用户,但我获得了Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\wamp\www\ticketing\newcustomer.php on line 11
我不知道错误是什么,因为我拥有正确的连接凭据,而且就我所知,SQL查询看起来很好。
<?php
session_start();
$con = mysqli_connect("localhost", "root", "", "ticketing");
$username = $_POST['username'];
$password = $_POST['pass'];
$fullname = $_POST['fullname'];
$query = mysqli_query($con,"INSERT INTO customer (username, password, fullname)
VALUES ($username, $password, $fullname)");
if (!mysqli_query($query,$con)){
die ("An error in the SQL Query: " . mysqli_error());
}
?>
答案 0 :(得分:0)
你的变量被错误地注入,用一个&#39;来封装它们。像这样
$query = mysqli_query($con,"INSERT INTO customer (username, password, fullname)
VALUES ('$username', '$password', '$fullname')");
重要!首先像这样逃避变量
$username = mysqli_real_escape_string($con , $username);
$password = mysqli_real_escape_string($con , $password);
$fullname = mysqli_real_escape_string($con , $fullname);