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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Hello!!

 

Thanks alot for both replies, very helpful. It took me long to get back because it works on one page but it does not on the other, I've been busy trying to work out where else I have gone wrong.

 

Thanks again!!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. =/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.