Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 18th, 2010, 02:22 PM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch. 4 p.118-119

I wrote out this code and am getting an error:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE people_id = '2'' at line 1"

I've checked my table code and they were all correct... I'm pulling my hair out trying to figure this out. Here's my codes:

table2.php
Code:

<?php
$link =connection
	or die(mysql_error());
mysql_select_db("moviesite")
	or die(mysql_error());
	$query = "SELECT movie_name, movie_director, movie_leadactor " .
			"FROM movie";
			
$result = mysql_query($query, $link)
	or die(mysql_error());
$num_movies = mysql_num_rows($result);
$movie_header=<<<EOD
<h2><center>Movie Review Database</center</h2>
<table width="70%" border="1" cellpadding="2"
	cellspacing="2" align="center">
		<tr>
			<th>Movie Title</th>
			<th>Year of Release</th>
			<th>Movie Director</th>
			<th>Movie Lead Actor</th>
			<th>Movie Type</th>
		</tr>

EOD;

function get_director(){
	global $movie_director;
	global $director;
	
	$query_d = "SELECT people_fullname" .
				"FROM people " .
				"WHERE people_id = '$movie_director'";
	$results_d = mysql_query($query_d)
		or die(mysql_error());
	$row_d = mysql_fetch_array($results_d);
	extract($row_d);
	$director = $people_fullname;
}
function get_leadactor(){
	global $movie_leadactor;
	global $leadactor;
	
	$query_a = "SELECT people_fullname" .
				"FROM people " .
				"WHERE people_id = '$movie_leadactor'";
	$results_a = mysql_query($query_a)
		or die(mysql_error());
	$row_a = mysql_fetch_array($results_a);
	extract($row_a);
	$leadactor = $people_fullname;
}
$movie_details = '';
while ($row = mysql_fetch_array($result)){
	$movie_name = $row['movie_name'];
	$movie_director = $row['movie_director'];
	$movie_leadactor = $row['movie_leadactor'];
	
	get_director();
	get_leadactor();
	
	$movie_details .=<<<EOD
		<tr>
			<td>$movie_name</td>
			<td>$director</td>
			<td>$leadactor</td>
		</tr>
EOD;
}
	$movie_details .=<<<EOD
		<tr>
			<td>&nbsp</td>
		</tr>
		<tr>
			<td>Total :$num_movies Movies</td>
		</tr>
EOD;
$movie_footer ="</table>";
$movie=<<<MOVIE
	$movie_header
	$movie_details
	$movie_footer
MOVIE;
echo "There are $num_movies movies in our database";
echo $movie;
?>
moviedata.php
Code:
<?php
$connect = 
or die ("You do not have a server connection.");


mysql_select_db("moviesite");

$insert = "INSERT INTO movie (movie_id, movie_name, movie_type, " .
			"movie_year, movie_leadactor, movie_director) " .
			"VALUES (1, 'Bruce Almighty', 5, 2003, 1, 2), " .
			"(2, 'Office Space', 5, 1999, 5, 6), " .
			"(3, 'Grand Canyon', 2, 1991, 4, 3)";
$results = mysql_query($insert)
	or die(mysql_error());
	
$type = "INSERT INTO movietype (movietype_id, movietype_label) " .
		"VALUES (1, 'sci fi'), " .
		"(2, 'drama'), " .
		"(3, 'adventure'), " .
		"(4, 'war'), " .
		"(5, 'comedy'), " .
		"(6, 'horror'), " .
		"(7, 'action'), " .
		"(8, 'kids')";
$results = mysql_query($type)
	or die(mysql_error());
	
$people = "INSERT INTO people (people_id, people_fullname, " .
			"people_isactor, people_isdirector) " .
			"VALUES (1, 'jim carrey', 1, 0), " .
			"(2, 'tom shadyac', 0, 1), " .
			"(3, 'lawrence kasdan', 0, 1), " .
			"(4, 'kevin kline', 1, 0), " .
			"(5, 'ron livingston', 1, 0), " .
			"(6, 'mike judge', 0, 1)";
$results = mysql_query($people)
	or die(mysql_error());

	echo "data inserted successfully";
		
?>

Last edited by pschulze; October 18th, 2010 at 02:28 PM.
Reply With Quote
  #2 (permalink)  
Old October 18th, 2010, 03:29 PM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So, I figured out what my problem was: I forgot to leave a space after 'fullname' at the end of the line $query_d = "SELECT people_fullname" .
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 UserController.cs P.119-129 ralphbethke BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 34 February 19th, 2011 09:40 PM
Pg 118 DyerOppenheimer BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 6 February 17th, 2011 11:31 PM
Chapter 4 pp. 118-119 luciano991 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 August 13th, 2006 01:56 PM
P117-118 teldridge Dreamweaver (all versions) 1 November 18th, 2004 04:22 PM



All times are GMT -4. The time now is 12:40 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.