technickul Posted April 1, 2010 Share Posted April 1, 2010 Can someone point me in the direction as to how can I pull information from a database and set the values in the form using that information? I know I will have to use a query and thats not the part I need help with its setting the text box values I don't know how to go about doing it. What I'm trying to do ultimately is create an edit account page where the user information is pulled in and they can modify it as they see fit. I've searched google quite a bit but when ever I search I always get the opposite of what I need. thanks! Link to comment https://forums.phpfreaks.com/topic/197192-database-information-to-html-form/ Share on other sites More sharing options...
darkagn Posted April 1, 2010 Share Posted April 1, 2010 Let's assume you have created a select query and retrieved the results into an associative array called $row. Here is how you set the values to the text boxes: $id = $row["USER_ID"]; if($id < 0) $username = 'New User'; else $username = $row["USERNAME"]; echo "<input type='text' value=$id name='id' />"; echo "<input type='text' value=$username name='username' />"; and so on. Basically the value setting will allow you to initialise your text boxes (or any other input for that matter) to a value, and the name field is used to retrieve it after the form is posted like so: if(isset($_POST["submit"])) { $id = $_POST['id']; $username = $_POST['username']; // send the details to the database. } Link to comment https://forums.phpfreaks.com/topic/197192-database-information-to-html-form/#findComment-1035066 Share on other sites More sharing options...
technickul Posted April 1, 2010 Author Share Posted April 1, 2010 Thanks thats much appreciated! Link to comment https://forums.phpfreaks.com/topic/197192-database-information-to-html-form/#findComment-1035067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.