Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 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 7th, 2009, 08:42 PM
Registered User
 
Join Date: Apr 2009
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
Question Chapter 12 update_user.php issues

I seem to be having a problem with both the code in the book and the downloaded code in Chapter 12. The update_user.php file is performing incorrectly.

When I update user information from the admin screen, all users in the table get updated with the new information... eg. if I change a first name to fred... everyone in the db's first name becomes fred. I assume there is an issue with the query...

here is the code from WROX

// No errors so enter the information into the database.

PHP Code:
   if (!empty($password)) {
            
$query 'UPDATE site_user SET
                    password = PASSWORD("' 
.
                        
mysql_real_escape_string($password$db) . '")
                WHERE
                    user_id = ' 
$user_id;
            
mysql_query($query$db) or die(mysql_error());
        }

        
$query 'UPDATE site_user u, site_user_info SET
            username = "' 
mysql_real_escape_string($username$db) . '",
            first_name = "' 
mysql_real_escape_string($first_name$db) . '",
            last_name = "' 
mysql_real_escape_string($last_name$db) . '",
            email = "' 
mysql_real_escape_string($email$db) . '",
            city = "' 
mysql_real_escape_string($city$db) . '",
            state = "' 
mysql_real_escape_string($state$db) . '",
            hobbies = "' 
mysql_real_escape_string(join(', '$hobbies), $db) . '"
          WHERE
            u.user_id = ' 
$user_id;
        
mysql_query($query$db) or die(mysql_error());
        
mysql_close($db); 
anyone know how to fix this?

-K
Reply With Quote
  #2 (permalink)  
Old May 7th, 2009, 08:46 PM
Registered User
 
Join Date: Apr 2009
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
Default misformed query...

I've figured this out...


it looks like there needs to be a join to the site_user_info table or else the entire table gets updated...

Guess this qualifies as errata.

I edited the query to look like this and it works fine now.

PHP Code:

(snip)
$query 'UPDATE 
                    site_user u JOIN site_user_info i ON u.user_id = i.user_id 
                SET
                    username = "' 
mysql_real_escape_string($username$db) . '",
                    first_name = "' 
mysql_real_escape_string($first_name$db) . '",
                    last_name = "' 
mysql_real_escape_string($last_name$db) . '",
                    email = "' 
mysql_real_escape_string($email$db) . '",
                    city = "' 
mysql_real_escape_string($city$db) . '",
                    state = "' 
mysql_real_escape_string($state$db) . '",
                    hobbies = "' 
mysql_real_escape_string(join(', '$hobbies), $db) . '"
                  WHERE
                    u.user_id = ' 
$user_id
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
Chapter 1 - PHP installation issues Abelmiah BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 June 21st, 2009 05:01 PM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
Chapter 12 update_account.php file andrene BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 25th, 2005 07:00 PM
Chapter 12 - useraccount.php buzzuh BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 September 3rd, 2004 02:53 PM
Chapter 12 Transact-Article.php czambran BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 June 17th, 2004 01:58 PM



All times are GMT -4. The time now is 02:44 AM.


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