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?
Cant get result from dynamically populated drop down list
Moderator: General Moderators
-
madan koshti
- Forum Commoner
- Posts: 50
- Joined: Fri Jun 06, 2008 4:25 am
Re: Cant get result from dynamically populated drop down list
pls paste full code..
Re: Cant get result from dynamically populated drop down list
<?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> </p>
<p> </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> </p>
</body>
</html>
//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> </p>
<p> </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> </p>
</body>
</html>