SteveMann Posted February 20, 2010 Share Posted February 20, 2010 Maybe I am asking the wrong question, but I've spent an hour looking through the forum here and can't find anything to answer my question. I have a form in my HTML file, and data in a database. Is here a way that I can put data from the database into the form for display or editing? I have the data entry *into* my database working pretty well, and now I am building an admin page where I can call up a record from the database and edit it. I suspect that I need to create the table in the PHP section after I read the data from the database. Is this correct or do I need to do more reading? TIA Steve Link to comment https://forums.phpfreaks.com/topic/192699-newbie-here-can-i-put-data-into-a-form/ Share on other sites More sharing options...
mapleleaf Posted February 20, 2010 Share Posted February 20, 2010 For example having done the query: <input name="first_name" type="text" value="<?php echo $row['first_name'];?>"> Link to comment https://forums.phpfreaks.com/topic/192699-newbie-here-can-i-put-data-into-a-form/#findComment-1015148 Share on other sites More sharing options...
Goafer Posted February 20, 2010 Share Posted February 20, 2010 If the query hasnt been performed the above response will launch an error about unset variables so make sure you protect it: value="<?php if(isset($row['first_name'])) { echo $row['first_name']; } ?>" or use: if(!$result) { $row = new array(); } or similar Link to comment https://forums.phpfreaks.com/topic/192699-newbie-here-can-i-put-data-into-a-form/#findComment-1015200 Share on other sites More sharing options...
SteveMann Posted February 20, 2010 Author Share Posted February 20, 2010 Thanks, but I already do a query to generate a CSV file and to show the data, but I want to pre-populate a form for editing. In other words, I want to use the same form as the 'data entry --> post' form, but ask for a key (record number in this case), then retrieve that row of data and populate the same form for editing. Can even do that? I am thinking that I have to build the form dynamically in PHP, but I still don't know how to fill the field in the form. TIA Steve Link to comment https://forums.phpfreaks.com/topic/192699-newbie-here-can-i-put-data-into-a-form/#findComment-1015244 Share on other sites More sharing options...
jl5501 Posted February 20, 2010 Share Posted February 20, 2010 The form can be the exact same form you use for the original entries, with the value attribute filled in, in one of the ways that have been suggested, using the array values from the database record Link to comment https://forums.phpfreaks.com/topic/192699-newbie-here-can-i-put-data-into-a-form/#findComment-1015247 Share on other sites More sharing options...
SteveMann Posted February 21, 2010 Author Share Posted February 21, 2010 Doh! Thanks... Link to comment https://forums.phpfreaks.com/topic/192699-newbie-here-can-i-put-data-into-a-form/#findComment-1015516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.