Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 24th, 2008, 05:00 PM
Registered User
 
Join Date: Nov 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 3, Page 110

I am working on exercise 3 of Chapter 3 on page 110 and am having some trouble. When I run the program I encounter the following 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 '1' at line 4"

The script looks something like this:
Code:
<?php
//connect to MySQL
$connect = mysql_connect("mysql", "username", "password") 
  or die("Hey loser, check your server connection.");

//make sure we're using the right database
mysql_select_db("moviesite");

$offset=$_REQUEST['offset'];
$query="SELECT movie_name, movie_year
        FROM movie
        ORDER BY movie_name
        LIMIT $offset,1";
$results=mysql_query($query)
  or die(mysql_error());
echo "<table>\n";
while ($rows=mysql_fetch_assoc($results)) {
  echo "<tr>\n";
  foreach($rows as $value) {
    echo "<td>\n";
    echo $value;
    echo "</td>\n";
  }
  echo "</tr><br />\n";
}
echo "</table>\n";
echo "<a href='page.php?offset=0'>Page1</a><br />";
echo "<a href='page.php?offset=1'>Page2</a><br />";
echo "<a href='page.php?offset=2'>Page3</a><br />";
?>
Perhaps someone can find the problem and help me out. Of course I changed the login information for this post. As a note... Everything else I have done up to this point has worked wonderfully.
  Spam!  
Old March 2nd, 2011, 10:06 AM
michieltam
Guest
 
Posts: n/a
Lightbulb Solution Chapter 3 exercise 3

I solved the solution on the following way.
I first made a new page (try1.php) with code:
Code:
<a href='select2.php?offset=0'>Page 1 </a><br/>
<a href='select2.php?offset=1'>Page 2 </a><br/>
<a href='select2.php?offset=2'>Page 3 </a><br/>
and then the solution of exersice3 in the page select2:
Code:
<?php
//connect to MySQL
$host="localhost";
$user="root";
$pass="qwerty";
$connect =mysql_connect($host, $user, $pass) or 
	die ("Hey loser, check your server connection.");

//makes the database moviesite the active database.
mysql_select_db("moviesite");

//get our starting point for the query through the URL variable "offset"
$offset=$_REQUEST['offset'];
$query="SELECT	movie_name, movie_year  
		 	FROM		movie
		 	ORDER BY	movie_name
			LIMIT		$offset,1";		
$results = mysql_query($query)
	or die (mysql_error());

echo "<table>";
while ($row = mysql_fetch_assoc($results)) {
	echo "<tr>";
	foreach ($row as $val) {
		echo "<td>";		
		echo $val;
		echo "</td>";
	}
	echo "</tr><br/>";
}
echo "</table>";

echo "<a href='select2.php?offset=0'>Page 1 </a><br/>";
echo "<a href='select2.php?offset=1'>Page 2 </a><br/>";
echo "<a href='select2.php?offset=2'>Page 3 </a><br/>";

?>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 7 - page 212 asplundo BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 February 2nd, 2008 06:56 AM
Chapter 5 Page 151 angelojr BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 2 June 12th, 2007 08:15 AM
Chapter 7 Try It Out page 218 drumdiva BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 3 March 19th, 2007 08:35 PM
Chapter 5 page 151 aztek BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 4 July 27th, 2006 06:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.