如此处所示,如果存在与 $member_id 匹配的数字 id,则删除该记录并且 $res 评估为 TRUE。如果表包含一个'member_id',它是一个字符串,例如 abc1234,它只会在我通过将 $member_id 括在引号'$member_id' 中来创建一个字符串时删除,这将删除所有匹配项,但是当 $res 总是评估为 TRUE 时,如果不匹配没有被删除(因为它应该),但用户得到一个“$member_id”。已从成员表中删除”消息。我希望这很清楚。
<?php
$member_id = "";
require("connect.php");
if (isset($_POST['member_id']))$member_id = fix_string($_POST['member_id']);
$sql=("DELETE FROM members WHERE member_id = $member_id");
$res = mysqli_query($con,$sql);
**if($res) {
echo "member with ID of ".$member_id." has been removed from members table";
} else {
echo "member was not deleted";
}**
function fix_string($string) {
if (get_magic_quotes_gpc()) $string = stripslashes($string);
return htmlentities ($string);
}
?>