Jump to content

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))

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.