crmamx Posted February 6, 2011 Share Posted February 6, 2011 I can add and delete data from my table. Now I need to be able to change one or more fields in an entry. So I want to retrieve a row from the db, display that data on a form where the user can change any field and then pass the changed data to an update.php program. I know how to go from form to php. But how do I pass the data from retrieve.php to a form so it will display? Do I use a URL and Get? Can I put the retrieve and form in the same program? Quote Link to comment https://forums.phpfreaks.com/topic/226872-last-step-updating-data-in-tablepassing-data/ Share on other sites More sharing options...
denno020 Posted February 6, 2011 Share Posted February 6, 2011 It's exactly the same as INSERT INTO, however you use UPDATE. Example: UPDATE (table) SET (column1) = (value from form) , (column2) = (value from form) WHERE id = (edited row_id) Denno Quote Link to comment https://forums.phpfreaks.com/topic/226872-last-step-updating-data-in-tablepassing-data/#findComment-1170627 Share on other sites More sharing options...
crmamx Posted February 6, 2011 Author Share Posted February 6, 2011 Thanks Denno, but I guess my request was not clear. retrieve.php will get the data from the db. form1.html will display the retrieved data. update.php will update the db. How do I get the retrieved variables from retrieve.php to form1.html? Quote Link to comment https://forums.phpfreaks.com/topic/226872-last-step-updating-data-in-tablepassing-data/#findComment-1170632 Share on other sites More sharing options...
denno020 Posted February 6, 2011 Share Posted February 6, 2011 Oh I see.. Well you can't have form1.html as a HTML file, it will need to be php. You then include retreive.php. If your form code, you will add the value="" property to each form field, and then inside the doube quotes for each value, you will echo the php variable that holds the correct text for that field. Example: You pull a name from the database and display it in the form //connect to mysql //run query to grab the information from the database //loop through the query result set, putting each column into it's own variable //you should have a variable $name = $row["name"]; //start printing all of your form code //the HTML/PHP code for the name text field will be <input type="text" name="name" value="<?php echo $name; ?>"/> //end your form printing. So you can see I've got lots of pseudo code above, but that's because I'm assuming you already know how to complete those parts. Hope that helps Denno Quote Link to comment https://forums.phpfreaks.com/topic/226872-last-step-updating-data-in-tablepassing-data/#findComment-1170640 Share on other sites More sharing options...
crmamx Posted February 6, 2011 Author Share Posted February 6, 2011 Well you can't have form1.html as a HTML file, it will need to be php. You then include retreive.php. If that is the case, why do I need an include? Example: You pull a name from the database and display it in the form //connect to mysql //run query to grab the information from the database //loop through the query result set, putting each column into it's own variable //you should have a variable $name = $row["name"]; //start printing all of your form code //the HTML/PHP code for the name text field will be<input type="text" name="name" value="<?php echo $name; ?>"/> //end your form printing. Can I do it like this? retrieve_data.php // php retrieve data // html create form and echo data into form, action=update.php method=post update.php //grab variables using $_POST['var_name']; //Update db Quote Link to comment https://forums.phpfreaks.com/topic/226872-last-step-updating-data-in-tablepassing-data/#findComment-1170655 Share on other sites More sharing options...
denno020 Posted February 6, 2011 Share Posted February 6, 2011 lol. You can. I was going to suggest that, but then I figured you might like to keep it separate so that it was easy to understand. As retrieve.php doesn't really hint at their being a form inside it. But yes, you can echo the form out in retrieve.php most definitely. Denno Quote Link to comment https://forums.phpfreaks.com/topic/226872-last-step-updating-data-in-tablepassing-data/#findComment-1170656 Share on other sites More sharing options...
crmamx Posted February 6, 2011 Author Share Posted February 6, 2011 Many Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/226872-last-step-updating-data-in-tablepassing-data/#findComment-1170660 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.