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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Valtros
Forum Newbie
Posts: 3
Joined: Thu Feb 04, 2010 1:04 pm

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

Post 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);
?>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post by AbraCadaver »

Count your parentheses and get an editor with syntax highlighting.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post by AbraCadaver »

And really the or die(mysql_error()) should go on the query since that's not returning a valid result.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Valtros
Forum Newbie
Posts: 3
Joined: Thu Feb 04, 2010 1:04 pm

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

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post 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());
    }
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Valtros
Forum Newbie
Posts: 3
Joined: Thu Feb 04, 2010 1:04 pm

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

Post 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
Post Reply