Fill textfield with data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asai
Forum Commoner
Posts: 43
Joined: Tue May 04, 2010 6:24 am
Location: Norway

Fill textfield with data

Post by asai »

Hi

Is it possible to fill data from a mysql query into a textfield and then update the mysql table?

First of all I have tried to fill data like this:

Code: Select all

<html>
<head>
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<?php

$id   = $_POST['id'];

include './config/config.php';
include './config/opendb.php';

$result = mysql_query("SELECT * FROM RegTable WHERE Id = '$id'") 
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {

$respons  = $row['Responsible'];

}
?>

<TABLE WIDTH=30% BORDER=0 CELLPADDING=0 CELLSPACING=0 STYLE="page-break-before: always">
<COL WIDTH=128*>
<COL WIDTH=128*>

<TR VALIGN=TOP>
<TD WIDTH=50%>
<p>Responsible: </p></TD>

<TD WIDTH=50%>
<P><input type="text" size="30" maxlength="30" id="$respons" name="responsible"></P>
</TD>
</TR>
</TABLE>
</html>
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: Fill textfield with data

Post by pbs »

First I would recommend you to use mysqli_ instead of mysql_ functions, as mysql_ functions are depricated.

You need to add value attribut of text box

Code: Select all

<input type="text" size="30" maxlength="30" id="responsible" name="responsible" value="<?php echo $respons;?>">
Also, as query will return only one record, so you can use mysql_fetch_row() instead of mysql_fetch_array();

Hope this will help you.
Post Reply