Jump to content
xisto Community
Sign in to follow this  
lonebyrd

Help With Registration Page, Access Denied.

Recommended Posts

I'm coming up with an error that I can't figure out in my registration page. Below I've given the error message and the code.

Warning: mysql_connect(): Access denied for user: 'nobody@localhost' (Using password: NO) in /home/lonebyrd/public_html/db_connect.php on line 33Access denied for user: 'nobody@localhost' (Using password: NO)


$Host = "localhost"; // define host name (default: localhost)$User = "$lonebyrd_razmo"; // define database username$Password = "$****"; // define database password$Database = "$lonebyrd_ftv"; // define database namemysql_connect($host, $user, $password) or die (mysql_error());mysql_select_db($database) or die (mysql_error());?>

Now, I've tried making a new user in Sql cpanel and giving it a new password to make sure I had everything correct, because at first it was wrong. But that didn't make a difference. I just can't figure this out. I don't know if it has anything to do with me using my roomates computer. But I don't see why that would make a difference. This was a prewritten script I found somewhere, and it was wrong to begin with, so I had to fix it, but it doesn't seem I'm doing a good job.

Share this post


Link to post
Share on other sites

lonebyrd, I am not sure if I can help at present, but could you tell us which one is the line number 33 in your db_connect.php.

This line:
mysql_connect($host, $user, $password) or die (mysql_error());
Or the one following it:
mysql_select_db($database) or die (mysql_error());

I am not sure it would help, but as far as I know, the use of these set of fuctions is as follows:

$conn = mysql_connect($host, $username, $password); mysql_select_db($dbname, $conn); 
And later you can use it for querying by:
mysql_query($query, $conn); 
Of course, I am not sure this is the problem, and hence, it would help if you could tell which line is line number 33, because it is failing exactly at that point.

This was a prewritten script I found somewhere, and it was wrong to begin with, so I had to fix it, but it doesn't seem I'm doing a good job.

Could you also show what the original script was?
Another thing you can do is wait for some one who has more expertise to come over this thread and answer your question. :unsure:

Share this post


Link to post
Share on other sites

Look at your own code here:

$Host = "localhost"; // define host name (default: localhost)

$User = "$lonebyrd_razmo"; // define database username

$Password = "$****"; // define database password

$Database = "$lonebyrd_ftv"; // define database name

 

mysql_connect($host, $user, $password) or die (mysql_error());

mysql_select_db($database) or die (mysql_error());[/b]

$host, $password, and $user have no values this is what caused the error either change this

$Host = "localhost"; // define host name (default: localhost)$User = "$lonebyrd_razmo"; // define database username$Password = "$****"; // define database password$Database = "$lonebyrd_ftv"; // define database name
to this

$host = "localhost"; // define host name (default: localhost)$user = "$lonebyrd_razmo"; // define database username$password = "$****"; // define database password$database = "$lonebyrd_ftv"; // define database name
or change this

mysql_connect($host, $user, $password) or die (mysql_error());mysql_select_db($database) or die (mysql_error());
to this

mysql_connect($Host, $User, $Password) or die (mysql_error());mysql_select_db($Database) or die (mysql_error());
Variables in PHP or in most other languages are case sensitive so $Host is not the same as $host or $HOST or anyother combination of lower or uppercase.

Share this post


Link to post
Share on other sites

Well, that didn't work. There was more to the script than that. At the beginning, it tells me to include another script that it had (a good size one), which holds some admin info along with some other information. I will include both scripts. First is the original db connection script, and second is the additional script it includes.

The original db connect script:

include("mojt_db.php");define("HOST", "$localhost"); // define host name (default: localhost)define("USER", "$lonebyrd_razmo"); // define database usernamedefine("PASSWORD", "$****"); // define database passworddefine("DATABASE", "$lonebyrd_ftv"); // define database name$db=mysql_connect(HOST, USER, PASSWORD); // connecting to the databasemysql_select_db(DATABASE, $db);?>

Here is the 'mojt_db.php' as asked for above:
$AdminName = "Rikki "; // define administrator name$AdminUserName = "lonebyrd "; // define admin user name$AdminPassword = "**** "; // define admin password$AdminEmail = "lonebyrd@yahoo.com "; // define admin email$AdminPanel = "login/admin.php"; // define path to the admin panel [without / at the end]$SiteUrl = "ftv.astahost.com "; // define full site address, ex. http://mysite.com = "FTV "; // define what will shell be display as site name$ContactEmail = "razmodat@aol.com "; // define which email address will be used for contact address$SupportEmail = "razmodat@aol.com "; // define which email address will be used for support address$Copyright = "2006 "; // define site copyright, set by user$Poweredby = "Powered by eVPortal."; // define powered by message (please don't remove this!)$MojtDir = "public_html "; // define directory where MoJT LS is installed [without / at the end]$CookieTime = "3600"; // define cookie time (in seconds)$FirstPage = "index.html "; // define your first protected page$db_host = "localhost"; // define host name (default: localhost)$db_username = "lonebyrd_razmo"; // define database username$db_password = "**** "; // define database password$db_name = "lonebyrd_ftv"; // define database name?>

It's probably something really simple that I'm missing, but I just don't see it. Being fairly new to this stuff, I love this forum for the help that I get.

Share this post


Link to post
Share on other sites

There are two ways to 'fix' this.
One change this

define("HOST", "$localhost"); // define host name (default: localhost)define("USER", "$lonebyrd_razmo"); // define database usernamedefine("PASSWORD", "$****"); // define database passworddefine("DATABASE", "$lonebyrd_ftv"); // define database name
to
define("HOST", "$db_host"); // define host name (default: localhost)define("USER", "$db_username"); // define database usernamedefine("PASSWORD", "$****"); // define database passworddefine("DATABASE", "$lonebyrd_ftv"); // define database name
or two (one is preferable)
define("HOST", "localhost"); // define host name (default: localhost)define("USER", "lonebyrd_razmo"); // define database usernamedefine("PASSWORD", "****"); // define database passworddefine("DATABASE", "lonebyrd_ftv"); // define database name

Share this post


Link to post
Share on other sites

Houdini, I must have been typing my post when you posted yours :unsure: . That was exactly the problem though. I didn't realize it was so specific. Once I changed those though I had an error with my other script about an unexpected '?' on my last line. Where else am I supposed to put the ?>...? Any way that's another script for another time. Thanks for the help.

Share this post


Link to post
Share on other sites

Arrg. I feel so dumb. I did not notice the capitalizations. Good catch Houdini. PHP is case sensitive.

 


Actually it is not.. I have my modules and it worked whatever the case is..

Maybe in some tweak settings or in safe mode the PHP parser turns into case sensitive one.

 

I am using a self compiled php 5 and apache 2 bin/cgi

 

--

 

well the error was simply that on some flavor of PHP.. using define with variables in different files yields nulls..

I never use a define statement when the variable value is easily available..

 

I only use defines if the variable will come from the database..

 

---

cheers..

 

define("HOST", "$localhost"); // define host name (default: localhost)define("USER", "$lonebyrd_razmo"); // define database usernamedefine("PASSWORD", "$****"); // define database passworddefine("DATABASE", "$lonebyrd_ftv"); // define database name

$db_host = "localhost"; // define host name (default: localhost)$db_username = "lonebyrd_razmo"; // define database username$db_password = "**** "; // define database password$db_name = "lonebyrd_ftv"; // define database name

please see that you have define a variable $db_host and yet the variable you pass to the define HOST is $localhost. $localhost is not the same as "localhost" since the first one is a variable named localhost and the last one is the value localhost.

 

please see also the username, the variable define to hold the username is$db_username and yet the one use in the define is $lonebyrd_razmo which is a new null variable..

 

and so goes on..

 

define("HOST", "$db_host"); // define host name (default: localhost)define("USER", "$db_username"); // define database usernamedefine("PASSWORD", "$****"); // define database passworddefine("DATABASE", "$lonebyrd_ftv"); // define database name

must be coded as

 

define("HOST", $db_host); // define host name (default: localhost)define("USER", $db_username); // define database usernamedefine("PASSWORD", db_password); // define database passworddefine("DATABASE", $db_name); // define database name

which passes all of the variables to the defines..

 

 

see, we must pass a variable not a string constant..

most user confuses between the variables and sting constant declarations..

 

=)

Edited by vhortex (see edit history)

Share this post


Link to post
Share on other sites

Actually it is not.. I have my modules and it worked whatever the case is..

Maybe in some tweak settings or in safe mode the PHP parser turns into case sensitive one.

This is not true of variables, and CONSTANTS are usually written in all uppercase to let you see easily that they are Constants. However a Constant is DEFINED either as lowercase or uppercase it is not called with a $ in front of it.

define ("AGE","29");echo AGE;//prints 29 to screen every time it is used
Rules that apply to variables

Begin with a $

Can be any length

Can include letters, numbers and underscores

They must begin with either a letter or an underscore

Upper and lowercase are NOT the Same

Now while you can define a constant with any combination of letter casing using does matter when you use them

<?phpdefine ("AGE","29");define ("age","42");echo AGE."<br />";//29echo age."<br />";//43echo "Age is ".Age;//will print Age is Ageecho "<br />AGE is ".AGE;//wil print AGE is 29echo "<br />age is ".age;//will print age is 42?>

Share this post


Link to post
Share on other sites

Well, I found the the problem with my '?' error. It wasn't actually at the end of my script. It was further up where I put a comment in that had a question mark but I forgot to put // before it. Just goes to show, you need to be careful while coding. Easy mistakes can be made if your not paying attention. I would have caught it quicker if I were using my own computer, but mine just died. I'm using my roomates, so I just installed PHP Designer 2006 (with her permission) and found it that way.

Share this post


Link to post
Share on other sites

PHP Designer is really great for finding little things like that, basically if your comment is not orangish in color then something is wrong. Just one forward slash / is not a comment (unless you follow it with either a * or another /. For checking code that others have written I just copy and paste into PHP Designer and can find many if not all flaws in code visually just by the highlighting within PHP Designer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.