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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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