Showing posts with label html forms. Show all posts
Showing posts with label html forms. Show all posts

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>


Thursday, December 8, 2011

how to use multiple forms on a single page

just name the submit button like this


1st form
<form action="abc.php" method="post"> 
<input type="text" name="abc">
<input type="submit" name="abc">
</form>
2nd form

<form action="abc.php" method="post"> 
<input type="text" name="def">
<input type="submit" name="xyz">
</form>
process the firm results
<?php
if(count($_POST)){
if (!empty($_POST["abc"])){
run your code here for 1st form
}
elseif(!empty($_POST["xyz"])){
run your code here for 2nd form
}
}
?>

you can place as many forms on a single page. As long as the submit name is different, only 1 form will be processed at a time.