Forum Moderators: coopster

Message Too Old, No Replies

php and mysql reading from db problem

this script does not work for some reason

         

flying monkey

9:20 pm on Jun 30, 2004 (gmt 0)

10+ Year Member



i have this script:

$db = mysql_connect("localhost", "root", "");
if (!$db){
echo "not working";
};
$name=mysql_select_db('greenbelt', $db);
if (!$name){
echo "not working";
};
$sql= mysql_query('Select * From index');

echo "<table border=0><tr><th colspan=2>Upcoming Events</th></tr>";

while (mysql_fetch_array($sql)) {
$id= mysql_result( $q, index.id); // get the field "number"
$title= mysql_result( $q, 2 ); // get the field "title"
$msg= mysql_result( $q, 3 ); // get the field "message"

echo "<tr><td>$id</td><th>$title</th><td>$msg</td></tr>";
}

mysql_close($db);

echo "</table>";

but it gives me this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\admin\admin.php on line 59

which would be this line:
while (mysql_fetch_array($sql)) {

what is wrong?

jatar_k

9:22 pm on Jun 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I have no idea, you need to get the return from mysql to get more info

change that line to

$sql= mysql_query('Select * From index') or die("query died: " . mysql_error());

then see what it says.

coopster

9:45 pm on Jun 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$sql= mysql_query('Select * From index')

index is not a good column name, it's a reserved word [dev.mysql.com].