Wrox Programmer Forums
|
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 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 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
 
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





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





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