Ok, Thank you very much!
What will that do?
| SitePoint Sponsor |
Ok, Thank you very much!
What will that do?
Ok, I get this error when I go there now:
No Database Selected
That help?![]()




It means it could not use the database you specified.
make sure the variable $db is set to the name of your database, if it's not set to anything, set it.
Ok, I have one, and I even dubled checked, and it still doesn't work!
Any other ideas?![]()





Ask the guy who set up your mySQL database for you to confirm the following information:
Your mySQL username
Your mySQL password
Your mySQL host (ask if it localhost or something else)
Your mySQL database name
Ok, I will ask AlexC right away, and see if that is all messed up!
I hope I get this working...![]()
Please?
Thanks,
~someonewhois
No body wants to help me?
OK, fine!
Thanks,
~someonewhois
In accesscontrol.php
dbConnect("coaster_coastert");
the arguement passed to dbConnect should be the name of your database
dbConnect("yourDbName");
Thank you very much!
I will try that soon!
Thanks,
~someonewhois
Ok, I fixed that and it still doesn't work!![]()

Ok - here's what to do. First of all, put the following script on your webserver - save it with the name phpinfo.php
Then copy the link to that page here - we can then tell you if MySQL is actually running.Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>PHP Info</title> </head> <body> <?php echo ( phpinfo() ); ?> </body> </html>
Now put up another script called dbconnect.php on your webserver
Edit the variables;Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Database Connect</title> </head> <body> <?php $server = "server name e.g. localhost"; $username = "database username"; $password = "database password"; $database = "database name"; if ( !$dbcnx = @mysql_connect($server, $username, $password) ) { echo ( "<p>Error1: <b>connecting</b> to database: " . mysql_error () . " - check \$server, \$username and \$password are <b>all</b> correct" ); } else if ( !$selectdb = mysql_select_db($database) ) { echo ( "<p>Error2: <b>selecting</b> database: " . mysql_error () . " - <b>\$database is wrong</b> - \$server, \$username and \$password <b>are correct!</b>" ); } else { echo ( "<h1 align=center>Connected to database successfully!!!</h1>" ); } ?> </body> </html>
$server - this is your database server name. You might be able to use just localhost, if it's on the same server as your webserver. It may be somethink else like "db.yourdomain.com:3306" - ask your hosting provider for the DNS name and port number for the MySQL server
$username - this is your MySQL username - this will probably not be the same as the name you use to ftp to your webserver. Ask your host for your MySQL user name
$password - as with username, this is probably not the same as your ftp login. Ask your host for your MySQL user password
$database - this is the name of your MySQL database on the MySQL server. Ask your host for the name of your MySQL database - this is not the same as the MySQL server name.
Once you have all those, put them in dbconnect.php right here;
Point your browser at http://www.yourdomain.com/dbconnect.php and see if it works. If not, copy the exact error message and past it here. We can then tell you what the problem is.Code:$server = "server name e.g. localhost"; $username = "database username"; $password = "database password"; $database = "database name";
The error was:Originally posted by HarryF
Ok - here's what to do. First of all, put the following script on your webserver - save it with the name phpinfo.php
Then copy the link to that page here - we can then tell you if MySQL is actually running.Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>PHP Info</title> </head> <body> <?php echo ( phpinfo() ); ?> </body> </html>
Now put up another script called dbconnect.php on your webserver
Edit the variables;Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Database Connect</title> </head> <body> <?php $server = "server name e.g. localhost"; $username = "database username"; $password = "database password"; $database = "database name"; if ( !$dbcnx = @mysql_connect($server, $username, $password) ) { echo ( "<p>Error1: <b>connecting</b> to database: " . mysql_error () . " - check \$server, \$username and \$password are <b>all</b> correct" ); } else if ( !$selectdb = mysql_select_db($database) ) { echo ( "<p>Error2: <b>selecting</b> database: " . mysql_error () . " - <b>\$database is wrong</b> - \$server, \$username and \$password <b>are correct!</b>" ); } else { echo ( "<h1 align=center>Connected to database successfully!!!</h1>" ); } ?> </body> </html>
$server - this is your database server name. You might be able to use just localhost, if it's on the same server as your webserver. It may be somethink else like "db.yourdomain.com:3306" - ask your hosting provider for the DNS name and port number for the MySQL server
$username - this is your MySQL username - this will probably not be the same as the name you use to ftp to your webserver. Ask your host for your MySQL user name
$password - as with username, this is probably not the same as your ftp login. Ask your host for your MySQL user password
$database - this is the name of your MySQL database on the MySQL server. Ask your host for the name of your MySQL database - this is not the same as the MySQL server name.
Once you have all those, put them in dbconnect.php right here;
Point your browser at http://www.yourdomain.com/dbconnect.php and see if it works. If not, copy the exact error message and past it here. We can then tell you what the problem is.Code:$server = "server name e.g. localhost"; $username = "database username"; $password = "database password"; $database = "database name";
Error1: connecting to database: Access denied for user: 'coasterthrills@localhost' (Using password: YES) - check $server, $username and $password are all correct
Ok, so what does that mean?
Also, I have already done the phpinfo thing...

It means that one (or may be more) of these three variables is wrong;
1. $server - you're using localhost - is the database running on the same server as your web server? And is it running on the default mysql port number 3306? Check with host.
2. $username - you're using coasterthrills - is that the correct name for your database user (remember - the login you use to access your site - for ftp or the control panel may be different to the database username). Check with host.
3. $password - the password for the database user may be wrong. Check with your host.
The easiest thing to do now is to send the dbconnect.php script, complete the values you've entered in it and ask them what's wrong.
Keep on trying (and keep on posting!- you're starting to looking like a serious contender to beat the "Kevins Tutorial Thread")
I already checked with Alex, and he says everything is fine!![]()

OK so what you should have in the script right now is this;
$server = "localhost";
$username = "coasterthrills";
$password = "******";
One question - are there any of the following characters in your password?
Apostrophe: '
Backslash: \
Quotes: "
Any of those are likely to make problems for MySQL. And watch out for spaces as well. If you have any of those, suggest you get the password changed.
Otherwise show Alex the latest script, give him the link to it running on your server and "Your problem mate" - either he's given you false information or there's a problem in the MySQL configuration / user setup.
Ok, simple as this!
I messed up completly!![]()
I had the databse name what should have been the user name, and the database was different!
I played around with that dbconnect.php file, and finally got it to work!
Thanks for everthing all!
Thanks,
~someonewhois
But it still says "No database selected" when I try to sign up!
The database is all set, I can connect to it, and I can seem to get it to work in other scripts!
I don't know whats wrong!
Thanks,
~someonewhois
Also, I can't make the ID table...![]()
It gives me an error!![]()
I made it, with some hassle...
1 more test!![]()

AWESOME
So you have managed to connect to the database. Now looking at Kevins "Managing User with Sessions" tutorial, I notice this;
What he's doing is making a function which you can re use, to select different databases.Code:<?php // db.php $dbhost = "localhost"; // ( this was $server above ) $dbuser = "user"; // ( this was $username above ) $dbpass = "password"; // ( this was $password above ) // $db was $database above function dbConnect($db="") { global $dbhost, $dbuser, $dbpass; $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass) or die("The site database appears to be down."); if ($db!="" and !@mysql_select_db($db)) die("The site database is unavailable."); return $dbcnx; }?>
If you want a hack this will guarantee it works;
This way it should be though is you have something like this in your pages;Code:<?php // db.php $dbhost = "localhost"; // ( this was $server above ) $dbuser = "user"; // ( this was $username above ) $dbpass = "password"; // ( this was $password above ) // $db was $database above function dbConnect($db="") { $db = "databasename"; // <<< insert your database name here global $dbhost, $dbuser, $dbpass; $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass) or die("The site database appears to be down."); if ($db!="" and !@mysql_select_db($db)) die("The site database is unavailable."); return $dbcnx; }?>
Code:include ( "db.php" ); dbConnect ( "coasterthrills" ); <<< or whatever your database name is.
Last edited by HarryF; Feb 21, 2002 at 19:56.
That didn't work!
I don't get any of this, why won't it work!?![]()
I'm wondering... it doesn't' seem to work...![]()
Try using:
instead of simply using:PHP Code:mysql_select_db($db, $dbcnx);
wherever it appears in your scripts;PHP Code:mysql_select_db($db);
OK, I'll try that!
Bookmarks