Populating drop down from mysql
Posted: Tue Sep 07, 2010 1:47 pm
Hi,
I have just started working on PHP and MySQL. I was trying to write a simple HTML page which would have a drop down to be populated from MySQL.
The drop down comes but with no values in it.
Could some one pls help with it?
Here is the code
<html>
<head>
<title>Test</title>
</head>
<body>
<form method="post" action="junk.php">
Date of Transaction : <input type="text" size="12" maxlength="12" name="DTxn"><br />
Amount:<input type="text" size="12" maxlength="36" name="amount"><br />
<select>
<?
//Select info from MySQL
$con = mysql_connect("localhost","test","test");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$kharcha_group = mysql_query("SELECT test_id,name FROM test_table");
while ($row = mysql_fetch_array($kharcha_group)) {
?>
<option value="<? echo $row[test_id]; ?>"><?echo $row[name];?></option>
<? } ?>
</select>
</form>
</body>
</html>
I have just started working on PHP and MySQL. I was trying to write a simple HTML page which would have a drop down to be populated from MySQL.
The drop down comes but with no values in it.
Could some one pls help with it?
Here is the code
<html>
<head>
<title>Test</title>
</head>
<body>
<form method="post" action="junk.php">
Date of Transaction : <input type="text" size="12" maxlength="12" name="DTxn"><br />
Amount:<input type="text" size="12" maxlength="36" name="amount"><br />
<select>
<?
//Select info from MySQL
$con = mysql_connect("localhost","test","test");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$kharcha_group = mysql_query("SELECT test_id,name FROM test_table");
while ($row = mysql_fetch_array($kharcha_group)) {
?>
<option value="<? echo $row[test_id]; ?>"><?echo $row[name];?></option>
<? } ?>
</select>
</form>
</body>
</html>