Jump to content

Database information to html form


technickul

Recommended Posts

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

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.
}

Archived

This topic is now archived and is closed to further replies.

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