Home > front end >  Store variable in href button
Store variable in href button

Time:11-11

I want to store my variable on my href

Current code

<input type=\"submit\" style=\"background-color:#bdffbe ; color: black; \" name =\"\" class=\"btn\" onclick=\"location.href='Patient_RescheduleAppt.php?id=".$row["AppointmentID"]."';\" value=\"Reschedule\"/> 

Code on Patient_RescheduleAppt.php

echo '<script language="javascript">';
echo 'alert("'.$_REQUEST['id'] .'")';
echo '</script>';

Currently when I click the alert didn't show anything

Full code

function patientAppts(){
        $m =date('m') ;
        $y =date('Y') ;
        $d =date('d') ;
        $date = $y."-".$m."-".$d;
        $sql = "SELECT PatientID FROM patients WHERE NRIC = '". $_SESSION['NRIC']. "' ";
        $result = @mysqli_query($this->conn, $sql);
        $re = mysqli_fetch_assoc($result);
        $id = $re['PatientID'];
        $sql2 =  "SELECT * FROM appointment JOIN doctor ON appointment.DocID = doctor.docID AND PatientID = $id AND Date >= '$date'";
        $result2 = @mysqli_query($this->conn, $sql2);
        
        while($row = mysqli_fetch_assoc($result2)){
            echo "<tr>
                <th style=\"text-align: right;\">
                ". $row['FirstName']." ". $row['LastName']."
                </th>
                <th style=\"text-align: right;\">
                ". $row['Date'] ."
                </th>
                <th style=\"text-align: right;\">
                ". date('H:i',strtotime($row['startTime'])) ." to ". date('H:i',strtotime($row['endTime'])) ."
                </th>
                <th style=\"text-align: right;\">
                ". $row['Location'] ."
                </th>
                <th style=\"text-align: right;\"> 
                <form  method=\"post\" action=\"Patient_RescheduleAppt.php\">
                    <input type=\"hidden\" name=\"appointmentID\" value=\"".$row['AppointmentID']."\"/>
                    <input type=\"submit\" style=\"background-color:#bdffbe ; color: black; \" name =\"\" class=\"btn\" onclick=\"location.href='Patient_RescheduleAppt.php?id=".$row["AppointmentID"]."';\" value=\"Reschedule\"/>     
                </form>
                </th>
                <th style=\"text-align: right;\">
                <form  method=\"post\" action=\"Patient_cancelAppt.php\" >
                    <input type=\"hidden\" name=\"appointmentID2\" value=\"".$row['AppointmentID']." \"/>
                    <input type=\"submit\" onclick=\"return confirm('Do you want to cancel your appointment')\" class='btn' title='Delete' data-toggle='tooltip'value=\"Cancel\" style=\" background-color:#d6d6d6; color: black;\" />              
                </form>
                </th>
                </tr>";
            }

I not sure why is it not working.

CodePudding user response:

There reason using you had use button as submit. So there are 2 possible way

  1. Handle click event with preventDefault and proceed
  2. Try a href instead of input submit

CodePudding user response:

You can try this

<input type="button" onclick="window.location.href = 'submit.php?id=<?php echo $row['id']?>&name=<?php echo $row['name']?>';" value="check"/>
  • Related