Jump to content

[SOLVED] Small MySQL Error


Datascalvo

Recommended Posts

Hi,

 

A friend of mine suggested me to visit this forum in order to get my problem solved.

 

I'm setting up a website where (offcourse) news should be posted (and to be read by others). Now when I go to http://localhost/ I get to see my news page as it should be. Then if I click on my news button (or first any other button, then the news button) I don't get to see my news page. Instead, I get the following MySQL error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\OT\xampp lite\htdocs\news.php on line 16

 

In news.php on line 16 I find the following, but I can't really figure out what is wrong with it:

 

while ($news_sql = mysql_fetch_array($news_query))

 

Also I got help on another forum where they said I was missing the news table in PHPMyAdmin. They told me to put the following code in my database, but it didn't work out:

 

DROP TABLE IF EXISTS `news`;

CREATE TABLE `news` (

`id` int(10) unsigned NOT NULL auto_increment,

`author` varchar(45) collate latin1_general_ci NOT NULL,

`title` varchar(45) collate latin1_general_ci NOT NULL,

`message` text collate latin1_general_ci NOT NULL,

`ip` varchar(45) collate latin1_general_ci NOT NULL,

`date` int(10) unsigned NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM AUTO_INCREMENT=32 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

-- Dumping data for table `news`

 

INSERT INTO `news` (`id`,`author`,`title`,`message`,`ip`,`date`) VALUES

(1,'Pixmo','Test News','Test msg for trying out news!','127.0.0.1',1175946074);

 

I'm using: phpMyAdmin - 2.10.1, MySQL client version: 5.0.41 and the latest Xampp Lite version.

 

Kind regards,

Datascalvo

 

(ps. sorry for the large post, I just tried to give as much information as I could)

 

 

Link to comment
https://forums.phpfreaks.com/topic/55123-solved-small-mysql-error/
Share on other sites

You're getting that error because setting $news_query has failed for some reason before that point, so you're trying to read data from an invalid source.  You should always check for errors when creating/debugging a program.  Use something like:

 

$news_query = mysql_query($your_query);
if (mysql_errno()) die(sprintf("Error: %s<br>\nQuery: %s<br>\n",mysql_error(),$your_query));
while ($news_sql = mysql_fetch_array($news_query))

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.