php文件无法向表中插入数据

时间:2018-10-20 12:56:54

标签: php mysql database

我需要支持,我的PHP文件无法将表单中的发布数据插入SQL, 但是当我使用常量值而不是$_POST['name']时,它可以工作。

<?php
$servername = "localhost";
$username = "hostingo_usrproj";
$password = "basel1990!";
$dbname = "hostingo_project";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 


$name         =$_POST['name'];
$email        =$_POST{'email'];
$usrpassword  =$_POST['usrpassword'];
$mobile       =$_POST['mobile'];



$sql = "INSERT INTO MyGuests (name, email, usrpassword, mobile )
VALUES ('$name', '$email', '$usrpassword', '$mobile')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
 }

$conn->close();
?>

1 个答案:

答案 0 :(得分:2)

$email        =$_POST{'email'];
根据我的想法,这是问题 试试这个

$email        =$_POST['email'];