Cant get result from dynamically populated drop down list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
link7722
Forum Newbie
Posts: 2
Joined: Sat Sep 06, 2008 2:44 am

Cant get result from dynamically populated drop down list

Post by link7722 »

I am using a drop down list which is dynamically populated from mysql succesfully with the following code
<select name="user" id="user">
<?php
while ($row = mysql_fetch_array($query)) {
echo "<option value=\"".$row['id']."\">".$row['username']."\n ";
}
?>
</select>
My problem is that when i use $username = $_POST['user']; to get the result from the list its empty.
What am i doing wrong?
madan koshti
Forum Commoner
Posts: 50
Joined: Fri Jun 06, 2008 4:25 am

Re: Cant get result from dynamically populated drop down list

Post by madan koshti »

pls paste full code..
link7722
Forum Newbie
Posts: 2
Joined: Sat Sep 06, 2008 2:44 am

Re: Cant get result from dynamically populated drop down list

Post by link7722 »

<?php
//session_start();
include('db_connection.php');
$query = mysql_query("SET NAMES 'UTF8'");
$query = mysql_query("SELECT username FROM $tbl_name");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {font-size: x-large}
-->
</style>
</head>

<body>
<div align="center"><span class="style1">ΔΙΑΛΕΞΕ ΟΝΟΜΑ ΚΑΙ ΒΑΛΕ ΤΟΝ ΚΩΔΙΚΟ ΣΟΥ</span>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form id="form1" name="form1" method="post" action="test1.php">
<table width="368" height="225" border="1" align="center" bgcolor="#99CC99">
<tr>
<td><strong>ΟΝΟΜΑ:</strong></td>
<td><label>
<select name="user" id="user">
<?php
while ($row = mysql_fetch_array($query)) {
echo "<option value=\"".$row['id']."\">".$row['username']."\n ";
}
?>
</select>
</label></td>
</tr>
<tr>
<td><strong>ΚΩΔΙΚΟΣ:</strong></td>
<td><label>
<input type="password" name="password" id="password" />
</label></td>
</tr>
<tr>
<td><label>
<input type="submit" name="button" id="button" value="ΕΙΣΟΔΟΣ" />
</label></td>
<td><label>
<input type="reset" name="button2" id="button2" value="ΑΚΥΡΟ" />
</label></td>
</tr>
<tr>
<td colspan="2"><div align="center"><a href="#" title="Μόνο ο Teo">Admin Login</a></div></td>
</tr>
</table>
</form>
<p>&nbsp;</p>
</body>


</html>
Post Reply