0

我让用户选择一个成员 ID,但我希望它删除相应的事件 ID (PK),因此该行被删除。你能提出一个简单有效的方法吗?这是我正在处理的代码,仅供参考。

前端。

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
Select member ID to <b> remove total and comment. </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['meid'];
$db1 = new dbme();
$db1->openDB();
$numofrows = $db1->delete_total($meid);//basically kill off the entire row
echo "Success. Number of rows affected:
<strong>{$numofrows}<strong>";

后端方法

function delete_total($mid, $meid) {


    $sql = "DELETE FROM memberevent WHERE mid = $mid"; // This is the bit I am head scratching, might there be a way to use mid to identify the corresponding PK (meid) to delete so the entire row is killed?
    $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 ;
 }

PS我知道它不能以目前的形式工作。

这是memberevent表结构。

meid (PK auto incr INT)
mid (int)
total (varchar)
comments (varchar)
ename (varchar)
4

0 回答 0