Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP 5.3
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP 5.3
This is the forum to discuss the Wrox book Beginning PHP 5.3 by Matt Doyle; ISBN: 978-0-470-41396-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 5.3 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 August 5th, 2012, 01:00 PM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 14: errors when logging in

I get 3 notices and 1 error and I cannot figure out why...

Notice: Use of undefined constant DB_DSN - assumed 'DB_DSN' in C:\xampp\htdocs\BookClub\DataObject.class.php on line 42

Notice: Use of undefined constant DB_USERNAME - assumed 'DB_USERNAME' in C:\xampp\htdocs\BookClub\DataObject.class.php on line 42

Notice: Use of undefined constant DB_PASSWORD - assumed 'DB_PASSWORD' in C:\xampp\htdocs\BookClub\DataObject.class.php on line 42

Connection failed: invalid data source name

I didn't get these messages during chapter 13 and I've rechecked all my code. I even downloaded the source code and used that (changing the database constants) and it still doesn't work.

Anyone else have the same problem?
Reply With Quote
  #2 (permalink)  
Old August 6th, 2012, 04:32 AM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

Make sure the constants (if in a seperate file make sure it's loaded) so they are defined before you use them.
Reply With Quote
  #3 (permalink)  
Old August 6th, 2012, 12:05 PM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have defined everything just as the book shows.

The root folder contains common.inc.php (the page header and footer functions), config.php (defining the constants), and the class and member files; all of which use require_once ("config.php").
The members folder contains login, logout, index, etc.; all of which use require_once ("../common.inc.php"). Since I'm new at this, I don't know what gets loaded or defined before being used.

I'm sure that this is causing the invalid source data error that I'm getting.
Reply With Quote
  #4 (permalink)  
Old May 27th, 2013, 05:19 AM
Registered User
Points: 13, Level: 1
Points: 13, Level: 1 Points: 13, Level: 1 Points: 13, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default I have THE SAME PROBLEM!

My code was working fine until I added the members folder. I decided to start from scratch using the zip source files and I still get the same errors as you. My config.php file is done correctly with my database, username, and password and all the files have the proper reference.
Another thing not working was the favorite genre fields when registering, the thing was completely blank.

Please someone check the source code for ch14 and test it. I cannot continue with the book without fixing this!
Reply With Quote
  #5 (permalink)  
Old May 28th, 2013, 07:36 AM
Registered User
Points: 13, Level: 1
Points: 13, Level: 1 Points: 13, Level: 1 Points: 13, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default OK, I fixed it.

The problem lies on page 408 of the book. It says to require the other 3 common files used in the application so they would be automatically loaded. This does not work for some reason, so the fix is to require all 4 files at the very top of the files inside the members folder.

So make sure all your files inside the members folder have this:

require_once( "common.inc.php" );
require_once( "config.php" );
require_once( "Member.class.php" );
require_once( "LogEntry.class.php" );

That takes care of dragongirl's error. My other issue was with the select box but that turned out to be a simple typo.
Reply With Quote
  #6 (permalink)  
Old February 21st, 2014, 03:51 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Chapter 14 app

I realize this thread is nearly nine months old, but I just got to Chapter 14 this month.

Anyway, placing the config.php file in the book_club directory along with require_once('config.php') in common.inc.php does in fact solve the paths problem; however, with respect to an actual e-commerce site, one is inviting problems by placing their config file (containing DB login param's) where a browser can access it. I don't know any tricks to physically read the contents of php files from a browser window, but that doesn't mean there isn't a script out there that can't. If you are going to place your config files inside the web root, perhaps naming it something really goofy might add security; however, I'm really surprised the author went to press with this file structure.

My solution to the path problem was to remove the members directory, locate all its files in the book_club directory and place the config file one level above the web root. Another way to do it would be to require (or include) the member files from another file inside the book_club directory.

I'd like to here from the author.

Thanks,
Hacker

P.S. At this point, I don't know what lies beyond page 427.

Last edited by Hacker; February 21st, 2014 at 04:03 AM.
Reply With Quote
  #7 (permalink)  
Old February 24th, 2014, 11:19 AM
Registered User
Points: 13, Level: 1
Points: 13, Level: 1 Points: 13, Level: 1 Points: 13, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default the config file

Hacker, u are right that its a horrendous idea to put the config file in such place. The way the pros do it is to create a CORE folder that contains a folder of your classes, a folder with the config file, and an init file (init.php). That init file should require config.php, start the session, and instantiate your classes.
I suggest you go to sunnytuts.com and do the Login and Registration Tutorial. That's where I learned really well how to build a simple site with the proper structure.
Reply With Quote
  #8 (permalink)  
Old February 24th, 2014, 09:51 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

surfinbird,

Thanks for the reference... I'll check it out just as soon as I finish $this->Chapter['fourteen']

I've finally reached the end of this convoluted thing which should probably require at least two reads for someone w/o a formal introduction to OOP. I'm on my second read but my first was interrupted just after we created the member subdirectory.

Thanks again,
Hacker

Last edited by Hacker; February 25th, 2014 at 04:29 PM.
Reply With Quote
  #9 (permalink)  
Old January 11th, 2015, 07:12 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XAMPP

I suspect that the problem occurs when using XAMPP to simulate a server.
The problem lies in this OTHER config file:
HTML Code:
 Cannot redeclare class Config in C:\xampp\php\pear\Config.php on line 44
The book recommend WAMP instead of XAMPP, maybe this is why the original files in the ch14.zip don't work.
Reply With Quote
  #10 (permalink)  
Old January 12th, 2015, 01:29 PM
Registered User
Points: 13, Level: 1
Points: 13, Level: 1 Points: 13, Level: 1 Points: 13, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default My tutorials

I made some tutorials on:
Login and Registration System
Posts/Twits system
Follow System like Twitter

www.pdotuts.com
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
CH 14 Pages 749-753 Compile Errors Razzy The Pug BOOK: Ivor Horton's Beginning Visual C++ 2005 1 March 28th, 2008 11:20 AM
Chapter 12 - Logging in mbrad BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 September 12th, 2007 04:22 PM
Chap 14 Errors russconnor BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 July 4th, 2006 08:11 AM
ch.14 file errors caseyc BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 10 February 28th, 2006 03:59 PM
Errors in Code; Chapter 14, pages 566-567 ou812 BOOK: Beginning ASP 3.0 10 June 20th, 2004 10:43 AM



All times are GMT -4. The time now is 12:07 PM.


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