0

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

I have problem with my database:

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/face911/public_html/fbvideos.uni.me/index.php on line 63

Can you help me with this? In database.txt I found this:

CREATE TABLE IF NOT EXISTS `videos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `videoid` varchar(50) CHARACTER SET latin1 NOT NULL,
  `views` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=32 ;

What do I need to do to make this script work?

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    Obvious guess: Your query has failed, returned a boolean false, and then you used that boolean false in further query operations. This means you have **NO** (or at least not enough) error handling in your code. Read up about [mysql_error()](http://php.net/mysql_error) and try again. – Marc B May 11 '12 at 00:01

1 Answers1

0

Oh. Seems like you ran mysql_fetch_object() for this query. This is wrong. Only select query are fetched. Please follow following.

mysql_connect("hostname","username","password");
mysql_select_db("db_name");
$q = "CREATE TABLE IF NOT EXISTS `videos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `videoid` varchar(50) CHARACTER SET latin1 NOT NULL,
  `views` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=32 ";

$result = mysql_query($q);
if($result)
echo "Done";

This will surely work.

Anwar
  • 672
  • 4
  • 16
  • If you are not sure that the error is due to the query provided above.. Please check in index.php line 63 where you have fetched and select query. Such errors occur when you fetch wrongly executed query or when the query is wrong... make sure that your query is right and also make sure you have used $var = mysql_query("Only Select Query goes here"); and then $row = mysql_fetch_object($var); Hope this helps – Anwar May 11 '12 at 00:13