1

我有一个 MySQL 数据库。

加载活跃的成员。

这些表有点像这样:

Table Name: recipients

Columns:    recipient_id
            member_id

然后我有一个名为recipients_banned The columns are the same as in 的表recipients

我想要做的是在表单(PHP)中有一个是/否字段,当单击该字段时,将所有member_idrecipients表中的人移动到recipients_banned表中。

对此的一些初始代码的任何帮助将不胜感激。如果不删除所有数据,这是否可能?请注意,recipients移动后应删除其中的行。

4

2 回答 2

1
recipients                     recipients_banned

recipient_id | member_id       recipient_id | member_id
------------------------       ------------------------
11           | 21              31           | 32
21           | 22              41           | 42

实际上,您没有详细解释您的问题。所以,我试图猜测你的问题并给你一些提示。例如,我们有一个名为form.php的 PHP 文件:

<form action="form.php?q=yes" method="get">
  Recipient ID: <input type="text" name="recipient_id">
  Member ID: <input type="text" name="member_id">
  <input type="submit" value="Move">
</form>

<?php
$con = mysqli_connect("$host", "$user", "$password", "$database");

$r = mysql_real_escape_string($_GET["recipient_id"];
$m = mysql_real_escape_string($_GET["member_id"];
$q = $_GET["q"];

if ($q = yes) {
    $i = "INSERT INTO `recipients_banned` ( `recipient_id` , `member_id` )
    VALUES (
      '$r' , '$m'
    );";

    $d = "DELETE FROM `recipients` WHERE `recipient_id` = $r AND `member_id` = '$m' LIMIT 1;";

    mysqli_query($con, "$i
    $d");
}

mysqli_close($con);
?>

如果我们尝试在Recipient ID字段中输入“21” ,在Member ID字段中输入“ 22”,然后单击Move按钮,数据库表的内容将如下所示:

recipients                     recipients_banned

recipient_id | member_id       recipient_id | member_id
------------------------       ------------------------
11           | 21              21           | 22
                               31           | 32
                               41           | 42

如果有问题,请随时修改此答案!

于 2013-04-08T11:04:47.327 回答
0

您的问题不清楚。例如,我们表格的数据是:

recipients               | recipients_banned
recipient_id | member_id | recipient_id | member_id
------------------------ | ------------------------
1            | 21        |
2            | 22        |

如果您只想在表单上有“是”“否”单选按钮,当您选择“是”按钮然后提交时,收件人表中的所有数据都将移动到收件人禁止表中,那么您应该最好试试这段代码。例如,我们有一个名为form.php的 PHP 文件:

<form action="form.php" method="get">
  <input type="radio" name="q" value="1">Yes<br />
  <input type="radio" name="q" value="0">No
  <input type="submit" value="Submit">
</form>

<?php
$con = mysqli_connect("$host", "$user", "$password", "$database");
$q = $_GET["q"];

if ($q == 1) {
    $i = "INSERT INTO `recipients_banned` ( `recipient_id` , `member_id` )
    SELECT recipient_id , member_id
    FROM `recipients`;";
    $d = "DELETE FROM `recipients`;";

    mysqli_query($con, "$i
    $d");

    echo '"recipients" data is moved to "recipients_banned"!';
} else if ($q == 0) {
    echo "Nothing is moved!";
}

mysqli_close($con);
?>

如果选择“No”然后提交,输出将是“Nothing ismoved!” . 但是,如果您在提交之前选择“是”,则看不见的数据库表结果将变为下表,并输出“收件人”数据已移动到“收件人禁止”!

recipients               | recipients_banned
recipient_id | member_id | recipient_id | member_id
------------------------ | ------------------------
                         | 1            | 21
                         | 2            | 22
于 2013-04-09T10:37:36.520 回答