我开始学习PHP和数据库连接,我花了将近一个小时试图弄清楚这是什么错误,但我终于放弃了。我阅读了很多文章并观看了很多视频,但都是徒劳的。请帮忙。 TIA。 我收到通知:未定义索引为错误。
以下是我的HTML代码:
<html>
<body>
<form action="insert.php" method="post"/>
Name:<input type="text" name="fname"> <br>
Age: <input type="text" name="age">
Sex: <input type="text" name="sex">
DOB: <input type="date" name="dob">
<input type="submit" value="Submit">
</body>
</html>
这是PHP代码
<?php
$servername = "localhost";
$user = "vks2910";
$pass = "********";
$db = "test2";
$mysqli = new mysqli($servername, $user, $pass, $db);
if($mysqli === false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}
else
{
echo("Congrats.");
}
$Name = mysqli_real_escape_string($mysqli, $_POST['Name']);
$Age = mysqli_real_escape_string($mysqli, $_POST['Age']);
$Sex = mysqli_real_escape_string($mysqli, $_POST['Sex']);
$DOB = mysqli_real_escape_string($mysqli, $_POST['DOB']);
$sql = "INSERT INTO bio (Name, Age, Sex, DOB) VALUES ('$Name', '$Age','$Sex', '$DOB' )";
if($mysqli->query($sql) === true)
{
echo ("Data recorded successfully.");
}
else
{
echo ("Error.");
}
$mysqli->close() ;
?>