当我提交表单时,我收到一条成功消息,但数据库中缺少数据,条目为空白。
基本上问题出在$ sql字符串中。
sql字符串将使VALUES回显正常,但数据库中的条目为空。
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = (string)$_POST["name"];
$email = (string)$_POST["email"];
$phone = (string)$_POST["phone"];
$sql = "INSERT INTO myTable (name,email,phone)
VALUES ('{$name}','{$email}','{$phone}')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
答案 0 :(得分:0)
我已将引号更改为文字&#39;并且为每个表单字段添加了id,我还删除了(字符串)CAST现在它可以工作。
<强> PHP:强>
File myFile;
myFile.setExecutable(true);
<强> HTML:强>
$name =$_POST['name'];
$email =$_POST['email'];
$phone =$_POST['phone'];