Forum Moderators: coopster

Message Too Old, No Replies

Selection Box

selection box generated from database

         

matudustrauss

8:53 am on Mar 17, 2008 (gmt 0)

10+ Year Member



When i load my page the selection box is there but there are no values from database. What did I do wrong?

my database is: access.
table: select.
field: code.
<html>

<body>

</select>
<form method="POST" action="access2.php">
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="form3.html">FORM1</a> ¦
<a href="test.html.php">TEST</a></a>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font size="4"><b>&nbsp; Industry Number&nbsp;
<input type="text" name="code" size="20"></b></font></p>
<p><font size="4"><b>&nbsp;
for issue&nbsp;
<select size="1" name="select">
<?
$link = mysql_connect()
or die('Could not connect: '. mysql_error());
mysql_select_db('access') or die('Could not select database');
$query = "SELECT `code` FROM `select` ";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($row = mysql_fetch_array($result,MSSQL_ASSOC)){
echo "<option >.$row['code'].</option>";
}
?></b></font></select></p>
<p><font size="4"><b>&nbsp;
If Other Specify&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="specify" size="20"></b></font></p>
<p><font size="4"><b>&nbsp;
</b></font></p>
<p>&nbsp;
<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>

[edited by: jatar_k at 1:54 pm (utc) on Mar. 17, 2008]
[edit reason] removed many nbsp for clarity [/edit]

omoutop

9:41 am on Mar 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



try this: $row = mysql_fetch_array($result)

Habtom

10:18 am on Mar 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to try to organize your code to make them more readable. It will be easier to spot errors. Assuming you have a proper connection, try the following, and post PHP errors you see related to the code.

<?php
$link = mysql_connect() or die('Could not connect: '. mysql_error());
mysql_select_db('access') or die('Could not select database');
$query = "SELECT `code` FROM `select` ";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
?>
<select size="1" name="select">
<?php
while ($row = mysql_fetch_array($result,MSSQL_ASSOC)){
echo "<option >".$row['code']."</option>";
}
?>
</select>

matudustrauss

7:29 am on Mar 25, 2008 (gmt 0)

10+ Year Member



I found the problem.the problem was that i was trying to run php on an html, php does not recognise anything thats not have its file extension(.php). to be able to run the form all i did was change my form to a php file.onother way was to edit the .htaccess file but its risky to do that.