In this part of the PHP tutorial, we will learn how to use List Box in the form. The values in the PHP List Box is retrieved from database and filled in the box.
In this part of the PHP tutorial, we will learn how to use List Box in the form. The values in the PHP List Box is retrieved from database and filled in the box.
Code
<?php
if(isset($_GET['roll']))
{
$username="root";
$password="";
$database="test";
$roll1=$_GET['roll'];
$chandle = mysql_pconnect("localhost", $username,
$password)
or die("Connection
Failure to Database");
mysql_select_db($database, $chandle) or die ("Database not found.");
$query1="select * from stud where roll='$roll1'";
$result=mysql_query($query1);
$x=0;
$num=mysql_numrows($result);
while($x<$num)
{
$f1 =
mysql_result($result,$x,1) or die("Failed Query");
echo "name is ".$f1;
$x++;
}
}
else
{?>
Select the roll <form
action='<?php
echo $_SERVER['PHP_SELF'];?>'>
<select name='roll' size="10">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
</select>
<input type="submit">
</form>
<?php }?>
Output
name is johan