Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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
  #1 (permalink)  
Old May 2nd, 2005, 04:12 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default ch 6 commit.php problem updating movie table

Hello everyone.

I made the changes to commit.php as shown on pg 186 of chapter 6, but I get a sql error when I try to edit a movie. The error message I get is : Invalid Query : 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 ''movie_name' = 'Test2', 'movie_year' = '2005', 'movie_type' = '

This is my query statement :
Code:
$sql = "UPDATE movie 
    SET 
        'movie_name' = '".$_POST['movie_name']."', 
        'movie_year' = '".$_POST['movie_year']."', 
        'movie_type' = '".$_POST['movie_type']."', 
        'movie_leadactor' = '".$_POST['movie_leadactor']."', 
        'movie_director' = '".$_POST['movie_director']."' 
    WHERE 
        'movie_id' = '".$_GET['id']."'";
 I have been looking at this for hours and can't find the error... my eyes are tired Any help would be appreciated. TIA
  #2 (permalink)  
Old May 2nd, 2005, 10:02 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found the cause of the sql error.

fieldnames should have back ticks around them instead of single quotes. (the back tick is the key to the left of the 1 key in the upper left corner.... in case you were wondering). Single quotes are fine for the values....but back ticks for field names.

The corrected code looks like this :

Code:
$sql = "UPDATE 
        `movie` 
    SET 
        `movie_name` = '".$_POST['movie_name']."', 
        `movie_year` = '".$_POST['movie_year']."', 
        `movie_type` = '".$_POST['movie_type']."', 
        `movie_leadactor` = '".$_POST['movie_leadactor']."', 
        `movie_director` = '".$_POST['movie_director']."' 
    WHERE 
        `movie_id` = ".$_GET['id'];
They look similar, but can be the difference between an updated table and a sql error.

Hope this helps someone.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Commit.PHP and Delete.PHP in WROX's book GiFos Beginning PHP 0 January 30th, 2007 10:51 PM
chapter 7 commit.php ratxamala BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 November 2nd, 2005 09:24 AM
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 PM
Chapter 6 commit.php czambran BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 4 October 3rd, 2004 10:20 PM
ch 7 page 208 commit.php pipdickenz BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 September 8th, 2004 12:08 PM





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