Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
This is the forum to discuss the Wrox book PHP and MySQL: Create-Modify-Reuse by Timothy Boronczyk, Martin E. Psinas; ISBN: 9780470192429
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 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 Display Modes
  #1 (permalink)  
Old January 14th, 2010, 07:01 PM
Registered User
 
Join Date: Jan 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default ch1 userId

Hi there,

I am busy implementing the login script in one of my websites. Everything is working fine and I understand the complete code except for one thing. And I want to understand everything before proceding.

The thing I just can't figure out is this:

On page six on the top of the page there is this code:

Code:
if ($field == 'userId'])
}
return $this->uid;
}
else
{
return $this->fields[$field];
}
The _set function, a little bit further down the code, checks if the array key exsists. Since neither the uid or userId is a part of the array in de constructor, I assume that it is impossible to set the uid or userId outside the class. I just can't figure out were in the code the userId is given a value. It must be there for a reason.

Can someone please tell me this?

Thanks

Last edited by nativerun; January 14th, 2010 at 07:04 PM.
Reply With Quote
  #2 (permalink)  
Old January 14th, 2010, 07:47 PM
Registered User
 
Join Date: Jan 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Oke, I have taken another look.
Can someone tell me if this is correct:

At the method save() the userId property is set. Then uid is returned.

But why is the save method refering to $this->userId and not directly to $this->uid?

Last edited by nativerun; January 14th, 2010 at 07:49 PM.
Reply With Quote
  #3 (permalink)  
Old January 15th, 2010, 12:29 AM
Authorized User
Points: 374, Level: 6
Points: 374, Level: 6 Points: 374, Level: 6 Points: 374, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: San Jose, Californina
Posts: 77
Thanks: 4
Thanked 6 Times in 6 Posts
Default

Hi nativerun,

In the database, in the USER table, user_id is AUTO_INCREMENT
When you insert a new user into the database
that new user gets assigned an ID. You can
retrieve that ID by doing a mysql_insert_id.
The author is doing that in this statement which
happens soon after the INSERT.
Code:
  
     $this->uid = mysql_insert_id($GLOBALS['DB']);
This is the only place the user id gets set.
We don't want it set anywhere else.

The book shows us User.php in chapter 1.
It also shows us User.php in chapter 2 because
for chapter 2 they need to make a couple of changes
with regard to user permissions.
This relates to your concern about use of
$this->userId instead of $this->uid in the save function.

The book is not consistent.
In chapter 1, in the save function, when they update
the database the last line is
Code:
   $this->isActive, $this->userId);
In chapter 2, same area, on page 36, and again on page 39,
they write it this way.
Code:
   $this->isActive, $this->permission, $this->uid);
As to which one the authors want to use, I don't know.
I use $this->userId. Now, I have tried it with $this->uid
and it worked, but keep in mind I am still in the class User.
Throughout the rest of the book, when they are in
some different class, they use $user->userId. When the
__get method sees userId it will return the uid, so you
are still getting at the uid value in all cases.
He does talk about $uid and the magic methods briefly at
the top of page 9.

I hope this helps.

By the way, there are some other issues in this book that
you might want to take a look at for chapter 1.
They are discussed in this forum. A couple that I am involved
in are:

Chapter 1 - Login not checking for active status?
see errata. Wrox acknowledged this problem.

User registration forgotpass.php
see errata. Wrox acknowledged this problem.

(Ch.1 Conflicting Info) This should be the Greatest PHP & mySQL Book - EVER
Reply With Quote
The Following User Says Thank You to kenj For This Useful Post:
nativerun (January 15th, 2010)
  #4 (permalink)  
Old January 15th, 2010, 08:38 AM
Registered User
 
Join Date: Jan 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Kenj,

Thank you for taking the time to write this down.
It is clear to me were and how the uid is given a value.

I was wondering what exacly the $this->userId was for. It is perfectly clear now. It is there to be able to get the uid outside the class. Don't know why I missed the point.

Thank you for explaining that inside the class $this->uid would work just as well as the $this->userId. I can sleep well now ;)

I had a look at all the errata before I started to use the code, so that should be allright.

Cheers

Last edited by nativerun; January 15th, 2010 at 08:52 AM.
Reply With Quote
Reply


Thread Tools
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
How to get current userid? nunokotzen BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 December 15th, 2009 05:14 PM
Possible Error? - CH1 Regiser.php ArthurDent BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 2 August 12th, 2008 03:50 AM
Ch1 MySQL returns Error 1046: No database selected aiche_ag BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 October 1st, 2007 03:47 PM
Ch1, why using CollectionBase class? NewTitle2007 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 August 5th, 2007 07:32 AM
UserId/Computer Name mrookey SQL Server ASP 1 August 2nd, 2005 08:23 AM



All times are GMT -4. The time now is 10:47 AM.


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