Page 1 of 1

Warning: mysql_fetch_array(): supplied argument is not a val

Posted: Thu Feb 04, 2010 1:21 pm
by Valtros
Hi im trying to code my website but each time i visit the page im getting this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in page.php on line 8.
So i added in "or die(mysql_error()" And now it is saying this:
Parse error: syntax error, unexpected '{' in page.php on line 8

I do not no what is wrong, please can you help me.

This is the code for the page that gives the error.

Code: Select all

<?php
$session=session_id();
include('includes/mysql.php');
$sql="SELECT * FROM development";
$result=mysql_query($sql);
 
while($rows = mysql_fetch_array($result) or die(mysql_error())
{ 
echo "<div class=\"red\">".$rows['name']."</div><br />".$rows['message']."<br /><br /><br /><br />";
}
?>
The code for mysql.php is (Login info changed):

Code: Select all

<?php
$con = mysql_connect("localhost:3333","USER","PASSWORD");
if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
mysql_select_db("my_website", $con);
?>

Re: Warning: mysql_fetch_array(): supplied argument is not a val

Posted: Thu Feb 04, 2010 1:23 pm
by AbraCadaver
Count your parentheses and get an editor with syntax highlighting.

Re: Warning: mysql_fetch_array(): supplied argument is not a val

Posted: Thu Feb 04, 2010 1:25 pm
by AbraCadaver
And really the or die(mysql_error()) should go on the query since that's not returning a valid result.

Re: Warning: mysql_fetch_array(): supplied argument is not a val

Posted: Thu Feb 04, 2010 1:29 pm
by Valtros
Ok thank you for the QUICK reply! and i added the extra ) to line 7 but now it is saying

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in page.php on line 7
No database selected

I thought mysql.php selected the database.

Oh by the way i use Notepad++ it is syntax highlighting. i just been looking at too much code my eyes missed it.


Ok i saw your second post after i wrote this so i moved the code u said now all im getting is:
No database selected

Re: Warning: mysql_fetch_array(): supplied argument is not a val

Posted: Thu Feb 04, 2010 1:50 pm
by AbraCadaver
OK, keep with the debugging methodology (you need to do this with most things for error handling and debugging):

Code: Select all

$db = mysql_select_db("my_website", $con);
if (!$db)
    {
    die('Could not select database: ' . mysql_error());
    }

Re: Warning: mysql_fetch_array(): supplied argument is not a val

Posted: Thu Feb 04, 2010 2:00 pm
by Valtros
Ok i FIXED it now.

The database was called "my_websites" NOT "my_website"

Thank you for the help!!! :)

I will be coming back here later surely ;) lol