Echo'Hello Programmers';
我正在处理记录删除功能。但是,我现在对重复发生的未定义索引问题感到有点迷失。
这是前端代码。
<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'操作符,或者将它们全部一起删掉?谢谢。
答案 0 :(得分:0)
变化:
$db1->delete_member($mid, $name, $address, $postcode, $photo);
要:
$db1->delete_member($mid);
并改变:
function delete_member($mid, $name, $address, $postcode, $photo) {
要:
function delete_member($mid) {
删除delete_member函数中的第1行到第4行