Associate
- Joined
- 22 Jan 2008
- Posts
- 1,311
- Location
- King's Lynn, Norfolk
Hi,
Having a bit of a headache with this at the moment.
Basically, I have a select field which is populated from a MySQL database, using PHP:
It populates the field just fine, but even though the value of the option looks fine, when passed, it passes a null value (or 0).
I've checked it isn't the Javascript behind it, as if I manually add an option, it passes it fine.
Here's my HTML for the section I'm talking about:
Having a bit of a headache with this at the moment.
Basically, I have a select field which is populated from a MySQL database, using PHP:
Code:
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("web", $con);
$sql="SELECT * FROM Results WHERE UserName = '".$q."'";
$result = mysql_query($sql);
echo
"<table id='SingleResult'>
<tr>
<th>Name</th>
<th>Result</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Result'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
It populates the field just fine, but even though the value of the option looks fine, when passed, it passes a null value (or 0).
I've checked it isn't the Javascript behind it, as if I manually add an option, it passes it fine.
Here's my HTML for the section I'm talking about:
Code:
<form id="ResultForm">
<select name="ResultList" onfocus="this.value=''" onchange="test(ResultList.value)">
<option> Choose... </option>
<?php
$con = mysql_connect('localhost', 'root', 'password');
//Selects the Database to use.
mysql_select_db("web", $con);
//Queries the database for results
$query="SELECT UserName FROM Results";
$result = mysql_query ($query);
while($nt=mysql_fetch_array($result))
{
echo "<option value=>$nt[UserName]</option>";
/* Option values are added by looping through the array */
}
//Closing the connection
mysql_close($con);
?>
</select>
</form>