I have a web page where you can add new users onto the system. One of the values that gets added to the database is an account type value which selected from a PHP drop down menu with values from a MySQL database. The problem that I am having is that when I try to add a record from the dropdown menu the value is always 'undefined', where as it should be the value that is selected (e.g. If Account Type 'Test' is selected, 'Test' should be the value inserted into the database)
Here is my code if anybody can help me with this problem:
mysql_connect('localhost', 'username', 'password');
mysql_select_db('databasename');
$sql="SELECT Id, AccountName FROM tblaccounts";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["Id"];
$accname=$row["AccountName"];
$options.="<OPTION VALUE=\"$id\">".$accname.'</option>';
}
Displaying the dropdown:
<div class="cp-controls-lrg left">
<p class="controls-margin">Account</p>
<select name="sel-account-name" id="sel-account-name" class="cp-controls-sml input-select input-select-xxlrg" tabindex="6">
<option value="0">Select Account
<?php echo $options?>
</select>
</div>
Let me know if you need any additional code to find out what the problem is, Many thanks!!