Friday, December 16, 2011

how to echo mysql retrieved value into a form as default value

// single field that has been retrieved from mysql database
$qry = mysql_query(" SELECT somefield FROM sometable WHERE something =  'some value'  ")or die(mysql_error());
$result = mysql_fetch_row($qry);
<form action="" method="">
<input type="" name="" value=" <?php echo $result[0]; ?>  ">
</form>
// in case of multiple values retrieved from mysql as a simple array

$qry = mysql_query(" SELECT somefield FROM sometable WHERE something =  'some value'  ")or die(mysql_error());
$result = mysql_fetch_array($qry);
<form action="" method="">
<input type="" name="" value=" <?php echo $result[0]; ?> "> //places the first value from mysql
<input type="" name="" value=" <?php echo $result[1]; ?> "> //places the second value
<input type="" name="" value=" <?php echo $result[2]; ?> "> //places the third value
<input type="" name="" value=" <?php echo $result[3]; ?> "> //places the fourth value and so on
</form>


No comments:

Post a Comment