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?

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>';

?>

 

 

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>

 

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']?>">/>

  • 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

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.