Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
Password Reminder
Register
| FAQ | Members List | Calendar | 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 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 Search this Thread Display Modes
  #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
Reply With Quote
  #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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
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



All times are GMT -4. The time now is 05:58 PM.


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