Jump to content

edit records and bring me back to same edit page


LittleB

Recommended Posts

Hello!!

 

I wonder if anybody can help.

 

I have a search.php page that displays a list of all records stored in a table. Clicking any of those records takes me to a page that allows me to edit that particular record, values of that racord are displayed on page. That works fine except for one part, once edited I would like to come back to the same edit page with all the values still displayed.

 

On search.php page the links to differnt records :

 

<a href="patient_form_edit.php?Patient_ID='.$data_search['Patient_ID'].'">..</a>

 

On my edit page:

 

...

$Patient_ID=$_GET['Patient_ID'];

$result_view=@mysql_query("SELECT * FROM Patient WHERE Patient_ID='$Patient_ID'");

$data=mysql_fetch_assoc($result_view);

...

 

if form is submitted

$pt_fName= $_POST['pt_fname'];

$pt_sName= $_POST['pt_sname'];

$pt_title= $_POST['pt_title'];

 

$query_pt = "UPDATE patient SET  pt_fName='$pt_fName',pt_sName='$pt_sName' ,pt_title='$pt_title' WHERE  Patient_ID='$Patient_ID'";

 

...

 

<form name="patientForm" method="post" action="patient_form_edit.php">

 

...

 

I know where I am going wrong; the beginning of the php I have $Patient_ID=$_GET['Patient_ID']; and after submitting the form the page doesnt seem to remember the $Patient_ID so it's an undefined index. Can anybody suggest a way of making the page remember the ID needed to load record values into the page?

 

 

Thanks you!!

 

 

In the form, add a hidden field -

<input type="hidden" name="Patient_ID" value="<?php echo $Patiend_ID; ?>" />

 

Then in your submission page, call -

$Patient_ID = $_POST['Patient_ID'];

 

By the way, to prevent SQL injection, use mysql_real_escape_string(). Look it up on php.net if you don't know it.

What he said - pass it with the hidden input field and use $Patient_ID = $_POST['Patient_ID']; to get the value.

 

And then after the UPDATE SQL part, use a header redirect like this:

 

header("Location: patient_form_edit.php?Patient_ID=$Patient_ID);

 

exit;

 

?>

 

 

Then when you go back to that page,

 

$Patient_ID=$_GET['Patient_ID'];

 

will grab the Patient_ID value from the URL and use it to re-query the database and display the data on the edit form.

It's basically like playing catch with a ball (the patient_id variable) and two people (the two scripts)....

 

The first person throws the ball up in the air (into the URL) and the second person catches it, then throws it back into the URL etc... as long as you're passing it back and forth correctly it should work. If not, try echoing the value of the patent_id variable instead of using the header () part, to see if it has a value.

It's basically like playing catch with a ball (the patient_id variable) and two people (the two scripts)....

 

The first person throws the ball up in the air (into the URL) and the second person catches it, then throws it back into the URL etc... as long as you're passing it back and forth correctly it should work. If not, try echoing the value of the patent_id variable instead of using the header () part, to see if it has a value.

Wow... nice analogy. =/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.