好的,所以我想创建一个更新表单,基本上更新我的表中的记录,但我无法做到这一点。我得到的错误如下:未定义的索引ID和所有..这是我的代码..我犯的错误是什么
<?php
// PHP code to update data from MySQL database table
if (isset($_POST['update'])) {
$hostname = "localhost";
$username = "root";
$password = "";
$databaseName = "winc sports";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
// get values form input text and number
$id = $_POST['Id'];
$fname = $_POST['Fname'];
$lname = $_POST['Lname'];
$age = $_POST['Age'];
$country=$_POST['Nationality'];
$phone=$_POST['PhoneNumber'];
$email=$_POST['Email'];
// mysql query to Update data
$query = "UPDATE `students` SET `Fname`='" . $fname . "',`Lname`='" . $lname . "',`Nationality`='" . $country . "',`PhoneNumber`=" . $phone . ",`Email`='".$email."',`Age`= " . $age . " WHERE `Id` = '" . $id . "'";
$result = mysqli_query($connect, $query);
if($result) {
echo 'Data Updated';
} else {
echo 'Data Not Updated';
}
mysqli_close($connect);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP INSERT DATA USING PDO</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="updating.php" method="post">
<input type="text" name="id" placeholder="Enter new ID"><br><br>
<input type="text" name="fname" placeholder="Enter new First Name"><br><br>
<input type="text" name="lname" placeholder="Enter new Last Name"><br><br>
<input type="number" name="age" placeholder="Enter new age" min="13" max="90"><br><br>
<input type="text" name="country" placeholder="Enter new Nationality"><br><br>
<input type="number" name="phone" placeholder="Enter new Phone Number"><br><br>
<input type="text" name="email" placeholder="Enter new Email"><br><br>
<input type="submit" name="update" value="update">
</form>
</body>
</html>
答案 0 :(得分:-1)
错误可能是您在POST数据中没有名为“Id”的索引。
尝试var_dump($ _ POST)以查看它实际包含的内容。
答案 1 :(得分:-1)
您的表单正在发布id
,而您的代码正在寻找Id
;案件很重要。