我已经彻底检查过我的数据库,表格和列名都是正确的。我的数据仍未插入。
这是我的PHP代码:
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "thehealthsync";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if(isset($_POST["t12"]))
{
$firstname = $_POST["t4"];
$lastname = $_POST["t5"];
$gender = $_POST["t6"];
$pin = $_POST["t7"];
$address = $_POST["t8"];
$email = $_POST["t9"];
$password = $_POST["t10"];
$conpass = $_POST["t11"];
if(!empty($firstname) && !empty($lastname) && !empty($gender) && !empty($pin) && !empty($address) && !empty($email) && !empty($password) && !empty($conpass))
{
if($password == $conpass)
{
$sql = "INSERT INTO userdata (firstname, lastname, gender, pin, address, email, password)
VALUES ('$firstname', '$lastname', '$gender', '$pin', '$address', '$email', '$password')";
}
else{
echo 'Password did not match';
}
}
else{
echo 'Some fields are empty';
}
}
$conn->close();
?>
答案 0 :(得分:1)
未插入,因为您不执行查询。在sql string之后
$sql = "INSERT INTO userdata (firstname, lastname, gender, pin, address, email, password)
VALUES ('$firstname', '$lastname', '$gender', '$pin', '$address', '$email', '$password')";
添加
mysqli_query($conn, $sql);
答案 1 :(得分:0)
您永远不会将查询发送到数据库,您只需设置$sql
变量。您必须致电mysqli_query
来实际执行查询。
答案 2 :(得分:0)
伙计,将mysqli_query($sql)
置于$sql
代码