Wrox Programmer Forums
|
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 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 December 29th, 2008, 07:47 PM
Registered User
 
Join Date: Dec 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default IM STUCK!!!

Hi everyone, im new to PHP and have found the code that i needed in this book. however i am having problems running the code and the mysql statements on my local machine and the remote server. can anyone help me out please?

Many thanks in advance.
 
Old December 29th, 2008, 07:48 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

It is typically good form to specify what code you are using, what you have attempted to do to run said code, and what errors you are getting. You have not provided any information that would be pertinent to solving your problem.

hth
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old December 30th, 2008, 07:58 PM
Registered User
 
Join Date: Dec 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default UPLOADING

Basically I was looking for user registration code and have found it in this book. However because I am totallt new to PHP/Mysql I do not knwo how to upload the completed code along with the sql table that has been provided. I do have a local installation of apache, Mysql, PHP (WAMP) but when i try to run the code locally it says 'cannot connect to database' error. could you please suggest the steps I need to make it run successfully.

Many thanks again for your reply previously it is very much appreciated.
 
Old December 30th, 2008, 08:13 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Just so you know I am not a PHP guy so I won't be able to provide you much in the way of code, luckily you aren't asking a language specific question ;]

What is the exact error? 'Can't connect to database' seems overly generic and there are only about 123459820 things that can cause this type of error. What does your connection string look like?

-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old December 30th, 2008, 08:19 PM
Registered User
 
Join Date: Dec 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for the quick reply, the code for connecting to the database looks like this:
<?php
// database connection and schema constants
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_SCHEMA', 'WROX_DATABASE');
define('DB_TBL_PREFIX', 'WROX_');

// establish a connection to the database server
if (!$GLOBALS['DB'] = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD))
{
die('Error: Unable to connect to database server.');
}
if (!mysql_select_db(DB_SCHEMA, $GLOBALS['DB']))
{
mysql_close($GLOBALS['DB']);
die('Error: Unable to select database schema.');
}
?>
 
Old December 30th, 2008, 08:30 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Alright, first off can you connect to MySQL, either through the command prompt shell or any of the gui tools, using localhost as the server name, and username and password as the username and password? If the answer is no then you need to either A) modify the PHP code so that it has a valid username and PW or B) Log in and create a Username and Password for your application to use. (I don't recommened using Username and Password either! ;])

Secondly, based upon the error you are getting, this line of code is being executed:
die('Error: Unable to connect to database server.');

So do this instead:

php Code:
if (!$GLOBALS['DB'] = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD))
{
    die('Error: Unable to connect to database server. MySQL Error is: ' . mysql_error());
}

This *should* print out a more detailed error message.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
The Following User Says Thank You to dparsons For This Useful Post:
cagaroos (December 30th, 2008)
 
Old December 30th, 2008, 08:42 PM
Registered User
 
Join Date: Dec 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

yes I can connect to the msql database via the command line. I have changed the connection code as you suggested, and the error that I get is:

Error: Unable to connect to database server. MySQL Error is: Access denied for user 'username'@'localhost' (using password: YES)
 
Old December 30th, 2008, 08:46 PM
Registered User
 
Join Date: Dec 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Do i have to create a database for the table that has been supplied with the code? What i did is basically load the code into the wamp folder for it to run and i have not created anything in mysql. does there need to be a corresponding database table in mysql for the pre-written scripts to access?
 
Old December 30th, 2008, 08:55 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The error you are getting either means the password is incorrect, the user doesn't exist, or the user is not allowed to access the server.

I am not sure how the code download is structured for this book but it would stand to reason that somewhere in there is a .SQL file that you could execute that will build all of the necessary tables, sprocs, and so on. So, to answer your question, yes you must setup MySQL with the proper database (Schema), tables, and so forth otherwise all of this is for not.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old December 31st, 2008, 06:16 PM
Registered User
 
Join Date: Dec 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

There is a SQL called tables, how can i execute this file for it to build all the necessary tables, sprocs etc?

Once again many thanks for your assistance





Similar Threads
Thread Thread Starter Forum Replies Last Post
im new with c# i need help tunisiano C# 7 February 17th, 2007 04:54 AM
im new here and i need ur help.... momoi Beginning VB 6 2 January 30th, 2006 11:44 PM
I've downloaded Jakarta-tomcat-5.5.9, now Im stuck xena BOOK: Professional Apache Tomcat 0 October 13th, 2005 08:05 AM
Data Shaping Problem .. im stuck! jeuriks SQL Server ASP 2 March 19th, 2004 11:09 AM
Im new in P2PForum darkdog BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 June 20th, 2003 01:11 PM





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