gpt4 book ai didi

javascript - 如何从 HTML-PhP 的表中的查询列表中运行特定查询

转载 作者:行者123 更新时间:2023-11-29 11:52:49 25 4
gpt4 key购买 nike

我有 2 个 MySQL 表,其中有 2 个相同的列,一个是 temptable,另一个是 permanenttable。我正在以表格的形式将 temptable 的内容显示到 php 表单。在这种形式中,我希望对于每个条目,我应该有 2 个选项,ApproveRevoke。我想要做的是,如果我单击批准,则该行的数据从temptable移动到permanenttable,或者如果我单击Revoketemptable 中的行被删除。我不知道如何实现它。表格如下所示:php form template

我最初想做的是单击“批准”,我处理 SQL 查询,然后重定向回此页面,当此页面再次打开时,我们按下按钮的行将被删除(因为它取自temptable)。

我很容易使用 SQL 查询,但我不明白如何将数据传递到下一个 php 文件,以便我可以识别要处理的行。

此外,任何有关如何实现这一目标的其他建议都会非常有帮助!

编辑 1:尝试的代码 - 表单:

    $query = "SELECT * from adddoctor";
$result = mysqli_query($conn,$query);
$i = 0;
while($row = mysqli_fetch_assoc($result)){
$pusername = $row['pusername'];
$dusername = $row['dusername'];
echo "<tr>";
echo "<td>".$pusername."</td>";
echo "<td>".$dusername."</td>";
echo "<form method = \"post\" action=\"approve.php\"">";
echo "<td><input name=\"Approve".md5($pusername + $dusername)."\" type=\"submit\" value=\"Approve\"/></form>";
echo "<form method = \"post\" action=\"revoke.php\">";
echo "<input name=\"Revoke".md5($pusername + $dusername)."\" type=\"submit\" value=\"Revoke\"/></td></form>";
echo "</tr>";
++$i;
}

批准:

$query = "Select * from adddoctor";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_assoc($result)){
$pusername = $row['pusername'];
$dusername = $row['dusername'];
$hash = md5( $pusername + $dusername);
$hash = "Approve" + $hash;
if(isset($_POST[$hash])){
$query = "INSERT INTO pdmap values('$pusername','$dusername')";
$result2 = mysqli_query($conn,$query);
$query = "Delete from adddoctor where pusername = '$pusername' and dusername = '$dusername'";
$result2 = mysqli_query($conn,$query);
}
}

最佳答案

不要使用+来连接,在php中使用.。在 php 'text' + 'text' = 0 中,我认为您混淆了 javascript 和 php。

表格:

$query = "SELECT * from adddoctor";
$result = mysqli_query($conn,$query);
$i = 0;
while($row = mysqli_fetch_assoc($result)){
$pusername = $row['pusername'];
$dusername = $row['dusername'];
echo "<tr>";
echo "<td>".$pusername."</td>";
echo "<td>".$dusername."</td>";
echo "<form method = \"post\" action=\"approve.php\"">";
echo "<td><input name=\"Approve".md5($pusername . $dusername)."\" type=\"submit\" value=\"Approve\"/></form>";
echo "<form method = \"post\" action=\"revoke.php\">";
echo "<input name=\"Revoke".md5($pusername . $dusername)."\" type=\"submit\" value=\"Revoke\"/></td></form>";
echo "</tr>";
++$i;
}

批准:

$query = "Select * from adddoctor";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_assoc($result)){
$pusername = $row['pusername'];
$dusername = $row['dusername'];
$hash = md5( $pusername . $dusername);
$hash = "Approve" . $hash;
if(isset($_POST[$hash])){
$query = "INSERT INTO pdmap values('$pusername','$dusername')";
$result2 = mysqli_query($conn,$query);
$query = "Delete from adddoctor where pusername = '$pusername' and dusername = '$dusername'";
$result2 = mysqli_query($conn,$query);
}
}

关于javascript - 如何从 HTML-PhP 的表中的查询列表中运行特定查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33727263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com