Jump to content

how to populate data into text fields on page load??


cluce

Recommended Posts

I am creating an account management page that shows the user's contact information and I would like to populate the textfields so that the user doesn't have to type in all his information when he wants to change something.  I want to have him type in only the information he wants to change or update. 

 

I already have the data displayed on the page. But now I would like to take the data and fill in the textfields with it. If somone show me a small example would appreciate it?

Link to comment
Share on other sites

Just query his information from the database and set the default values for the fields to his existing info

 

<?php

  $query = $db-query("SELECT * FROM users WHERE uid = '$userid'");
  $userinfo = $db->fetch_array($query);

  echo'
  <form method="post" action="'.$_SERVER['PHP_SELF'].'">

  <table>
    <tr><td><input type="text" name="username" value="'.$userinfo[username].'">
    <tr><td><input type="submit" name="submit" value="Update">
  </table>

  </form>';

?>

 

 

Link to comment
Share on other sites

Hi,

check this code

 

 

<?

$id=1;

$sql_sel="select username,email from tablename where id='$id'";

$res=mysql_query($sql_sel);

$row=mysql_fetch_array($res);

?>

 

  <form method="post" action="'.$_SERVER['PHP_SELF'].'">

 

  <table>

    <tr><td><input type="text" name="username" value="'.$row[username].'">

  <tr><td><input type="text" name="email" value="<?=$row['email']?>">

    <tr><td><input type="submit" name="submit" value="Update">

  </table>

 

  </form>

 

Link to comment
Share on other sites

here is what I have and I cant get it to display data in the fields. i know my querey works because I Am able to diplay data on page just not in the fields. 

//create query and retrieve record of user logged on 
//create and issue the query
    $SQL = "SELECT * FROM auth_users";
// WHERE username = '".$_SESSION['identity']."'";
   $result = mysqli_query($mysqli,$SQL);
   $row = mysqli_fetch_array($result);
   ///part of form code///
  <td bordercolor="#000000"><input name="firstname" type="text" id="firstname" size="30" maxlength="30" value="<?=.$row['f_name']?>">/>

Link to comment
Share on other sites

  • 2 years later...

hi, try this.............

 

<?php

#building connection from specified script

            #use db connection parameters

include("dbconnect.php");

 

#selecting all users for the table

$result = mysql_query("Select * from tblUsers WHERE UserID='SMUNTHALI' ORDER BY UserID ASC");

 

$row=mysql_fetch_array($result);

$f1=$row{'UserID'};    //getting user id

$f2=$row{'UserName'};  //getting username

?>

<html>

<head><title>display data to a form</title></head>

<body>

  <form method="post" action="display_form_data.php">

  <table>

    <tr><td>

<input type="text" name="UserID" value="<?php echo $f1 ?>"/>

</td></tr>

  <tr><td>

<input type="text" name="UserName" value="<?php echo $f2 ?>">

</td></tr>

    <tr><td><input type="submit" name="submit" value="Update"></td></tr>

  </table>

  </form>

</body>

</html>

<?php

mysql_close();

?>

 

 

Regards

Ulltimate Coder

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.