Q:

How to use a value i get from a form in another php

<?php

 if(isset($_POST['edit_button'])){
    $ID=$_POST['edit_button'];
    $query = "SELECT  PNAME , GENDER, AGE, ADDRESS , PHONENUMBER
    FROM PATIENT LEFT OUTER JOIN PHONENUMBER
    ON PID=EPID AND '$ID'=PID";

    $stid = oci_parse($conn, $query);
    oci_execute($stid);
    $row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);

        $patient_name= $row['PNAME'];
        $patient_gender= $row['GENDER'];
        $patient_address= $row['ADDRESS'];
        $patient_age= $row['AGE'];
        $patient_phone= $row['PHONENUMBER'];
    }
?>

 <?php
if(isset($_POST['Edit_Patient'])){
    $new_pname=$_POST['pName'];
    $new_pGender=$_POST['pGender'];
    $new_pAge=$_POST['pAge'];
    $new_pAddress=$_POST['pAddress'];
    $new_phone=$_POST['phone'];
    $update_query=" UPDATE PATIENT 
                   SET PNAME= '$new_pname', GENDER= '$new_pGender', AGE=$new_pAge, ADDRESS='$new_pAddress'
                   WHERE PID= '$ID'";
    $stid = oci_parse($conn, $update_query);
    $result=oci_execute($stid);
    if (!$result) {
        echo oci_error();   
    }

}

?>
THESE TWO PHPS ARE IN THE PHP FILE registration.php
So, my question is: i get the Id from the first php but i can't use in the second where both are in the same php file.Also, i tried putting the $ID=$_POST['edit_button']; above the if statement, but it gave me an error

A:

You need to assign $ID in one hidden field of Update Patient form. So when you submit that form you will get a value of $ID as follows:
Initialize $ID with blank value above the first if statement:
$ID = "";

Update Patient Form
<form>
...
<input type="hidden" name="patient_id" value="<?php echo $ID; ?>" />
...
</form>

Second If statement
if(isset($_POST['Edit_Patient'])){
    ...
    $ID = $_POST['patient_id'];
    ...
}

Hope this may helpful to anyone!

