回声“你好程序员”;
我正在研究记录删除功能。但是,我现在对反复出现的未定义索引问题有点迷茫。
这是前端代码。
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
Select member to <b> DELETE! </b>: <select name="mid">
<?php
while($row = mysqli_fetch_assoc($result))
echo "<option value='{$row['mid']}'>{$row['mid']} </option>";
?>
</select>
<input type="submit" value=">!DELETE!<" />
</form>
<?php
}
else
{
$mid = $_POST['mid'];
$name = $_POST['name'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$photo = $_POST['photo'];
$db1 = new dbmember();
$db1->openDB();
$numofrows = $db1->delete_member($mid, $name, $address, $postcode, $photo);
echo "Success. Number of rows affected:
<strong>{$numofrows}<strong>";
$db1->closeDB();
}
所以我们正在从下拉菜单中选择一个 ID。然后,当按下删除按钮时,我们将这个 ID 传递给类方法以执行删除。
function delete_member($mid, $name, $address, $postcode, $photo) {
$esc_name = mysqli_real_escape_string($this->conn, $name);
$esc_address = mysqli_real_escape_string($this->conn, $address);
$esc_postcode = mysqli_real_escape_string($this->conn,$photo);
$esc_photo = mysql_reali_escape_string($this->conn, $photo);
$sql = "DELETE FROM member WHERE mid = $mid";
$result = mysqli_query($this->conn, $sql);
if ($result) {
$numofrows = mysqli_affected_rows($this->conn);
return $numofrows;
}
else
$this->error_msg = "could not connect for some wierd reason";
return false ;
}
Notice: Undefined index: name in C:\xampp\htdocs\dbm\deletemember.php on line 120
也许我需要替换“Else”运算符,或者一起摆脱它?谢谢你。