Page 1 of 1

Fill textfield with data

Posted: Mon Jul 25, 2016 3:27 am
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>

Re: Fill textfield with data

Posted: Mon Jul 25, 2016 8:06 am
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.