无法使用 Javascript Link 提交我的表单

Unable to submit my form with Javascript Link

我尝试提交我的表单,该表单有两个不同的链接,指向删除和编辑 php 文件,但我注意到这些链接没有将单选按钮的值提交给 php 文件尤其是删除 php 文件。但是当我更改按钮的链接时,该值已提交。请问我不想使用按钮标签,我怎样才能使值通过我的链接传递到 php 文件?

表格如下:

<form action="del_cn_rec.php" method="POST" id="consignments" >
              <table id="example1" class="table table-hover table-bordered table-striped">
                <thead>
                <tr>
                  <th>ID</th>
                  <th>Consignment No</th>
                  <th>Sender</th>
                  <th>Reciever</th>
                  <th>Pickup Date/Time</th>
                  <th>Msg_Status</th>
                  <th>Status</th>
                  <th>Action</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                <?php 

                                                $sqlc="SELECT * FROM consignments";
                                                $resultc=  mysql_query($sqlc) or die(mysql_error());
                                                while($rwsc=  mysql_fetch_array($resultc)){
                                                echo "<tr>";
                                                    echo "<td><input type='radio' class='flat-red' name='cn_id' value=".$rwsc[0];
                                                    echo " /></td>";
                                                    echo "<td>".$rwsc[1]."</td>";
                                                    echo "<td>".$rwsc[16]." ".$rwsc[17]."</td>";
                                                    echo "<td>".$rwsc[21]." ".$rwsc[22]."</td>";
                                                    echo "<td>".$rwsc[6]." ".$rwsc[7]."</td>";

                                                    $sqli='SELECT * FROM admin_inbox WHERE cn="'.$rwsc[1].'"';
                                                    $resulti= mysql_query($sqli);
                                                    $rwsi= mysql_fetch_array($resulti);
                                                    $mstatus= $rwsi[4];
                                                    if("$mstatus" === "Unreplied"){
                                                    $moutput = "<span class='label label-danger'><i class='fa fa-circle'></i> Unreplied</span>";
                                                    }
                                                    if("$mstatus" === "Replied"){
                                                    $moutput = "<span class='label label-success'><i class='fa fa-check-circle'></i> Replied</span>";
                                                    }
                                                    if("$mstatus" === ""){
                                                    $moutput = "<span class='label label-warning'><i class='fa fa-circle-o'></i> No Message</span>";
                                                    }
                                                    echo "<td>".$moutput."</td>";

                                                    $status= $rwsc[9];
                                                    if("$status" === "Delivered"){
                                                    $output = "<span class='label label-success'><i class='fa fa-check-square-o'></i> Delivered</span>";
                                                    }
                                                    if("$status" === "On Hold"){
                                                    $output = "<span class='label label-danger'><i class='fa fa-hand-stop-o'></i> On Hold</span>";
                                                    }
                                                    if("$status" === "Arrived"){
                                                    $output = "<span class='label label-primary'><i class='fa fa-motorcycle'></i> Arrived</span>";
                                                    }
                                                    if("$status" === "In Transit"){
                                                    $output = "<span class='label label-warning'><i class='fa fa-truck'></i> In Transit</span>";
                                                    }
                                                    echo "<td>".$output."</td>";

                                                    echo "<td><a  href=\"javascript:{}\" onclick=\"askForEdit_Rec()\"><span class=\"label label-primary\"><i class=\"fa fa-edit\"></i> Edit Rec.</span></a></td>";
                                                    echo "<td><a  href=\"javascript:{}\" onclick=\"askForDelete_Rec()\"><span class=\"label label-danger\"><i class=\"fa fa-times\"></i> Delete Rec.</span></a></td>";
                                                    echo "</tr>";}
                ?>
                </tbody>
                <tfoot>
                <tr>
                  <th>ID</th>
                  <th>Consignment No</th>
                  <th>Sender</th>
                  <th>Reciever</th>
                  <th>Pickup Date/Time</th>
                  <th>Msg_Status</th>
                  <th>Status</th>
                  <th>Action</th>
                  <th>Action</th>
                </tr>
                </tfoot>
              </table>
             </form>
            </div>
            <script>
form=document.getElementById("consignments");
function askForEdit_Rec() {
    form.action = <?php echo json_encode($urlc); ?>;
    form.submit();
}

</script><script>
form=document.getElementById("consignments");
function askForDelete_Rec() {
    form.action="del_cn_rec.php";
    form.submit();
}

</script>

这里是删除 php 文件:del_cn_rec.php

<?php 
session_start();
include '_inc/dbconn.php'; 
$sql="SELECT * FROM admin WHERE id='1'";
$result= mysql_query($sql);
$rws= mysql_fetch_array($result);
$email_1= $rws[3];
$email_2= $rws[4];
$phone= $rws[5];
$address= $rws[6];
$url= $rws[7];
if(!isset($_SESSION['admin_login']))
header("location:$url/server-side");  
?>
<?php 
            $id=  mysql_real_escape_string($_REQUEST['cn_id']);
            $sql1="SELECT * FROM consignments WHERE id='$id'";
            $result1= mysql_query($sql1);
            $rwsn= mysql_fetch_array($result1);
            $cn= $rwsn[1];

            $sql2="DROP TABLE IF EXISTS ".$cn."status ";
            mysql_query($sql2) or die(mysql_error());

            $sql3="DROP TABLE IF EXISTS ".$cn."msg ";
            mysql_query($sql3) or die(mysql_error());

            $sql6 = mysql_query("SELECT * FROM admin_inbox WHERE cn='$cn'");
            if (mysql_fetch_row($sql6)){
            $sql4="DELETE FROM admin_inbox WHERE cn='$cn'";
            mysql_query($sql4) or die(mysql_error());
            }

            $sql5="DELETE FROM consignments WHERE id='$id' AND cn='$cn'";
            mysql_query($sql5) or die(mysql_error());

            //Consignment Remove Success Msg
            $msg = "<i class=\"fa fa-check\"></i> Consignment: $cn Has Been Successfully Deleted!";
            header("Location:$url/server-side/consignments?msg=$msg");

?>

这通常应该有效,只需确保您的 php 日志或生成的 html 中没有任何错误或通知,或者浏览器控制台。确保单选按钮的值填写在 html 中(也许您从 sql 得到错误的结果)。

此外,我希望您知道必须先 select 单选按钮,然后才单击 "Delete" 或 "Edit" link - 这有点令人困惑在这里,因为你把 link 放在每一行。单选按钮仅在 selected 时才发送值,否则它们甚至不会出现在 POST 数据中。

如果你想在每一行使用 link 而不先 select 单选按钮,你必须将 cn_id 作为参数传递给 askForDelete_Rec() 函数然后在那里使用它。输入类型="hidden" 可能对此有用,或者只是将其作为 GET 参数附加到操作中。