I am trying to create a select drop-down list using php. Every time i try, i get an error.
Here is my code:
The function:
function dropDown(){
$options="<select>";
$connect = mysql_connect('localhost','id','pass') or die ("couldn't connect!").mysql_error;
mysql_select_db('db') or die('could not connect to database!');
$sql="SELECT * FROM DESC";
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result)) { // this is line 60
$name=$row["name"];
$options.="<option value=\"$name\">".$name."</option>";
}
$options.= "</SELECT>";
return "$options";
}
and then i just call it in my code
<?php
include ('includes/functions.php');
// ...
$list = dropDown();
echo "$list";
// ...
?>
The error I get is:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/garagenj/public_html/dispatch/includes/functions.php on line 60
If your table name is
DESCthen that’s your problem. It’s all about namespacing. You can’t even have a field nameddesc, I’ve tried. It errors everytime