LittleB Posted May 3, 2009 Share Posted May 3, 2009 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!! Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 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. Quote Link to comment Share on other sites More sharing options...
seaweed Posted May 4, 2009 Share Posted May 4, 2009 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. Quote Link to comment Share on other sites More sharing options...
LittleB Posted May 4, 2009 Author Share Posted May 4, 2009 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!! Quote Link to comment Share on other sites More sharing options...
seaweed Posted May 4, 2009 Share Posted May 4, 2009 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 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. =/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.