kim de castro kim de castro - 6 months ago 25
MySQL Question

How to hide GET method Form or URL value?

I'm using datatables to display the list with "EDIT" button.
running it on localhost.

format I use to echo the details:

<a href="student_edit.php?studid='.$row['studid'].'">EDIT</a>


displaying the list(datatables) external

while( $row=mysqli_fetch_array($query) ) { // preparing an array

$nestedData=array();
$nestedData[] = $row["fname"];
$nestedData[] = $row["mname"];
$nestedData[] = $row["lname"];
$html = '<a href="student_edit.php?studid='.$row['studid'].'">EDIT</a>';
$nestedData[] = $html;
$data[] = $nestedData;
}


result:

http://sample.com/studid?=1


To get the data of student:

$id_get = $_GET['studid']; //GET THE ID VIA URL
$sql = "SELECT * FROM student_list WHERE id = '".$id_get."'";
$result = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_assoc($result)) {
$fname1=$row['FIRSTNAME'];
$mname1=$row['MIDDLENAME'];
$lname1=$row['LASTNAME'];
$gender1=$row['SEX'];
$addrc=$row['ADDRESS'];
}
?>


How is it possible to hide the Id Number in URL?

ASR ASR
Answer

Use POST method and a hidden input field for id. Something like,

while( $row=mysqli_fetch_array($query) ) {  // preparing an array

    $nestedData=array(); 
    $nestedData[] = $row["fname"];
    $nestedData[] = $row["mname"];
    $nestedData[] = $row["lname"];
    $html  = '<form action="student_edit.php" method="post" name="form_'.$row['studid'].'">';
    $html .= '<input type="hidden" name="studid" value="'.$row['studid'].'">';
    $html .= '<input type="submit" name="edit" value="EDIT">';
    $html .= '</form>';
    $nestedData[] = $html;
    $data[] = $nestedData;
} 

To get the data of student:

if(isset($_POST['edit']) && $_POST['edit'] == 'EDIT'){

    $id_get = $_POST['studid']; //GET THE ID VIA URL
    $sql = "SELECT * FROM student_list WHERE id = '".$id_get."'";
        $result = mysqli_query($conn,$sql);
        while ($row = mysqli_fetch_assoc($result)) {
            $fname1=$row['FIRSTNAME'];
            $mname1=$row['MIDDLENAME'];
            $lname1=$row['LASTNAME'];
            $gender1=$row['SEX'];
            $addrc=$row['ADDRESS'];
        }    
}