Populating drop down from mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
noviceuser082
Forum Newbie
Posts: 1
Joined: Tue Sep 07, 2010 1:39 pm

Populating drop down from mysql

Post by noviceuser082 »

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>
Post Reply