Hi! I'm trying to learn PHP but as proceed with tutorials I encounter more and more problems. and I'm not sure if they are arising from my mistakes because I just rewrite very simple tutorial excerisies.

I get this two errors when I load table1.php in my browser:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\table1.php on line 11

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\table1.php on line 25

I have created those three FIles :

createmovie.php - when i load it in browser i get "Movie database successfully created!" so no problem seems to be here

//create the main database if it doesn't already exist
$create = mysql_query("CREATE DATABASE IF NOT EXISTS moviesite")
	or die(mysql_error());
	//make sure taht recently made databse is the active one
//create movie table
$movie = "CREATE TABLE movie (
	movie_id int(11) NOT NULL auto_increment,
	movie_name varchar(255) NOT NULL,
	movie_type tinyint(2) NOT NULL default 0,
	movie_year int(4) NOT NULL default 0,
	movie_leadactor int(11) NOT NULL default 0,
	movie_director int(11) NOT NULL default 0,
	PRIMARY KEY (movie_id),
	KEY movie_type (movie_type,movie_year)
	$results = mysql_query($movie)
		or die (mysql_error());
//create movietype table
$movietype = "CREATE TABLE movietype (
	movietype_id int(11) NOT NULL auto_increment,
	movietype_label varchar(100) NOT NULL,
	PRIMARY KEY (movietype_id)
	$results = mysql_query($movietype)
		or die(mysql_error());
//create people table
$people = "CREATE TABLE people (
	people_id int(11) NOT NULL auto_increment,
	people_fullname varchar(255) NOT NULL,
	people_isactor tinyint(1) NOT NULL default 0,
	people_isdirector tinyint(1) NOT NULL default 0,
	PRIMARY KEY (people_id)
	$results = mysql_query($people)
		or die(mysql_error());
		echo "Movie database successfully created!";		  




//connect to mysql
$connect = mysql_connect("localhost", "bp5am", "bp5ampass")
	or die("Check your server connection");
//make sure we are using the right database

//insert data into movie table
$movie = "INSERT INTO movie (movie_id, movie_name, movie_type, " .
			"movie_year, movie_leadactor, movie_director) " .
			"VALUES (1, 'Bruce Almight', 5, 2003, 1, 2), " .
			"(2, 'Office sapce', 5, 1999, 5, 6), " .
			"(3, 'Grand Canyon', 2, 1991, 4, 3)";
			$results = mysql_query($insert)
				or die(mysql_error());
				//insert data into movietype table
$type = "INSERT INTO movietype (movietype_id, movietype_label) " .
		"VALUES (1, 'Sci-fi'), " .
		"(2, 'Drama'), " .
		"(3, 'Adventure'), " .
		"(4, 'War'), " .
		"(5, 'Comedy'), " .
		"(6, 'Horro'), " .
		"(7, 'Action'), " .
		"(8, 'Kids'), " .
		$results = mysql_query($type)
			or die(mysql_error());
		//insert data into people table		 
		$people = "INSERT INTO people (people_id, people_fullname, " .
					"people_isactor, people_isdirector) " .
					"VALUES (1, 'Jim Carrey', 1, 0), " .
					"(2,'Lawrence kasdan', 0, 1), " .
					"(3, 'Tom Shadyc', 0, 1), " .
					"(4,'Kevin Klein', 1, 0), " .
					"(5,'Ron Livingston', 1, 0), " .
					"(6,'Mike Judge', 0 , 1), " .
				$results = mysql_query($people)
					or die(mysql_error());
					echo "Data inserted successfully";


AND the last one


$link = mysql_connect("localhost", "bp5am", "bp5ampass")
	or die(mysql_error());
		or die(mysql_error());
$query = "SELECT movie_name, movie_director, movie_leadactor " .
"FROM movie";
$results = mysql_query($query, $link)
		or die(mysql_error());
$num_movies = mysql_num_rows($result);    //       <------------------LINE 11
<h2><center>Movie Review Database</center></h2>
<table width="70%" border="1" cellpadding="2" cellspacing="2" align="center"
<th>Year of release</th>
<th>Movie director</th>
<th>Movie lead actor</th>
<th>Movie type</th>
$movie_details = '';
while($row = mysql_fetch_array($result)) {       //  <---------------------LINE 25
	$movie_name = $row['movie_name'];
	$movie_director = $row['movie_director'];
	$movie_leadacotr = $row['movie_leadactor'];
	$movie_details .=<<<EOD
$movie_detalis .<<<EOD
<td>Total : $num_movies Movies</td>


I'm using the newest relaese of wampserver 2.0 (Apache2.2.8 ; PHP 5.2.5 ; MySQL 5.0.51a)
Although Excersis in my book are made on Apache(2.0.50.)PHP(5.0.0)MySQL(4.0.20)
Thanks for any help

Recommended Answers

you have mispelled your $results to $result on line 11.Just add a s on the end of $result.

Jump to Post

All 3 Replies

you have mispelled your $results to $result on line 11.Just add a s on the end of $result.

You missed off an 's' the variable you defined is $results but you keep calling $result, change it to $results or change the defined variable to $result.

$result[B]s[/B] = mysql_query($query, $link)
$num_movies = mysql_num_rows($result);

hope that makes sense,


Sorry, posted at the same time as ryan, at least now you're doubley as sure.

Thanks a lot guys! Funny how i spent few hours analyzing this cod and yet i coudn't find such a simple mistake

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.