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

时间:2015-11-16 01:32:41

标签: javascript php html mysql sql-server

我有2个MySQL表,它们有2个相同的列,一个是temptable,另一个是permanenttable。我以表格的形式向temptable表单显示php的内容。在这种形式中,我希望每个条目都有,我应该有2个选项,ApproveRevoke。我想要做的是,如果我点击Approve,那么temptable中该行的数据会移至permanenttable,或者如果我点击Revoke,则来自temptable被删除。 我不知道如何实现它。以下是表单的外观:php form template

我最初尝试做的是单击Approve,我处理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);
            }
        }   

1 个答案:

答案 0 :(得分:1)

不要在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);
    }
}