-1

I have tried to submit my form which is having two different links leading to the delete and edit php files but i noticed that the links do not submit the value of the radio button to php files especially the delete php file. But when i changed the links to buttons the value was submitted. Please i do not want to use the button tag, how can i make the value get across to the php files with with my links?

Here is the form:

<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>

Here is the Delete php file: 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");

?>
Daniel C.
  • 49
  • 1
  • 1
  • 6
  • If you're writing new code, **_please_ don't use the `mysql_*` functions**. They are old and broken, were deprecated in PHP 5.5 (which is so old it no longer even receives security updates), and completely removed in PHP 7. Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Jun 18 '17 at 23:26

1 Answers1

0

this should generally work, just ensure you don't have any errors or notices in your php log, or in the generated html, or any javascript errors in the browser console. Ensure that the value for the radio button is filled in the html (maybe you are getting wrong result from the sql).

Also I hope you know you have to first select the radio button and only after that click the "Delete" or "Edit" link - it is a little confusing here, since you put the link on every row. Radio buttons send values only when they are selected, otherwise they will not even appear in the POST data.

If you wanted to use the links on every row without first selecting the radio button, you have to pass the cn_id as a parameter to the askForDelete_Rec() function and then use it there. An input type="hidden" might be usefull for that, or just append it to the action as a GET parameter.

petrtvaruzek
  • 473
  • 5
  • 6