Welcome Guest ( Log In | Register )




                Web Hosting

2 Pages V   1 2 >  
Reply to this topicNew Topic
Help With Registration Page, Access Denied.
lonebyrd
post Jul 6 2006, 10:53 AM
Post #1


Premium Member
Group Icon

Group: Members
Posts: 302
Joined: 23-February 06
From: Northeastern Connecticut USA
Member No.: 11,487


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.

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


CODE
$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());

?>


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.
Go to the top of the page
 
+Quote Post
Vyoma
post Jul 6 2006, 11:25 AM
Post #2


Cosmic Overlord
Group Icon

Group: Members
Posts: 571
Joined: 26-November 05
From: Denver, Colorado, US
Member No.: 9,811
myCENTs:45.66


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:
CODE

$conn = mysql_connect($host, $username, $password);
mysql_select_db($dbname, $conn);

And later you can use it for querying by:
CODE

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.

QUOTE
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. smile.gif
Go to the top of the page
 
+Quote Post
Houdini
post Jul 6 2006, 12:04 PM
Post #3


Super Member
Group Icon

Group: Members
Posts: 572
Joined: 25-April 05
From: Nashville Tennessee
Member No.: 4,340


Look at your own code here:
QUOTE
$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
CODE
$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
CODE
$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
CODE
mysql_connect($host, $user, $password) or die (mysql_error());
mysql_select_db($database) or die (mysql_error());
to this
CODE
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.

Go to the top of the page
 
+Quote Post
lonebyrd
post Jul 6 2006, 12:12 PM
Post #4


Premium Member
Group Icon

Group: Members
Posts: 302
Joined: 23-February 06
From: Northeastern Connecticut USA
Member No.: 11,487


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:
CODE
include("mojt_db.php");

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

$db=mysql_connect(HOST, USER, PASSWORD); // connecting to the database
mysql_select_db(DATABASE, $db);

?>


Here is the 'mojt_db.php' as asked for above:
CODE
$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://www.mysite.com
$SiteName = "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.
Go to the top of the page
 
+Quote Post
Houdini
post Jul 6 2006, 12:34 PM
Post #5


Super Member
Group Icon

Group: Members
Posts: 572
Joined: 25-April 05
From: Nashville Tennessee
Member No.: 4,340


There are two ways to 'fix' this.
One change this
CODE
define("HOST", "$localhost"); // define host name (default: localhost)
define("USER", "$lonebyrd_razmo"); // define database username
define("PASSWORD", "$****"); // define database password
define("DATABASE", "$lonebyrd_ftv"); // define database name

to
CODE
define("HOST", "$db_host"); // define host name (default: localhost)
define("USER", "$db_username"); // define database username
define("PASSWORD", "$****"); // define database password
define("DATABASE", "$lonebyrd_ftv"); // define database name

or two (one is preferable)
CODE
define("HOST", "localhost"); // define host name (default: localhost)
define("USER", "lonebyrd_razmo"); // define database username
define("PASSWORD", "****"); // define database password
define("DATABASE", "lonebyrd_ftv"); // define database name
Go to the top of the page
 
+Quote Post
lonebyrd
post Jul 6 2006, 01:09 PM
Post #6


Premium Member
Group Icon

Group: Members
Posts: 302
Joined: 23-February 06
From: Northeastern Connecticut USA
Member No.: 11,487


Houdini, I must have been typing my post when you posted yours smile.gif . 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.
Go to the top of the page
 
+Quote Post
Vyoma
post Jul 6 2006, 01:18 PM
Post #7


Cosmic Overlord
Group Icon

Group: Members
Posts: 571
Joined: 26-November 05
From: Denver, Colorado, US
Member No.: 9,811
myCENTs:45.66


Arrg. I feel so dumb. I did not notice the capitalizations. Good catch Houdini. PHP is case sensitive.
Go to the top of the page
 
+Quote Post
vhortex
post Jul 7 2006, 11:35 AM
Post #8


Guilty Until Proven Innocent
Group Icon

Group: Members
Posts: 372
Joined: 13-April 05
Member No.: 3,937


QUOTE(Vyoma @ Jul 6 2006, 09:18 PM) [snapback]82123[/snapback]

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..

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


CODE
$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..

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


must be coded as

CODE
define("HOST", $db_host); // define host name (default: localhost)
define("USER", $db_username); // define database username
define("PASSWORD", db_password); // define database password
define("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..

=)

This post has been edited by vhortex: Jul 7 2006, 11:44 AM
Go to the top of the page
 
+Quote Post
Houdini
post Jul 7 2006, 01:12 PM
Post #9


Super Member
Group Icon

Group: Members
Posts: 572
Joined: 25-April 05
From: Nashville Tennessee
Member No.: 4,340


QUOTE
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.
CODE
define ("AGE","29");
echo AGE;//prints 29 to screen every time it is used
Rules that apply to variables
  1. Begin with a $
  2. Can be any length
  3. Can include letters, numbers and underscores
  4. They must begin with either a letter or an underscore
  5. 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
CODE
<?php
define ("AGE","29");
define ("age","42");
echo AGE."<br />";//29
echo age."<br />";//43
echo "Age is ".Age;//will print Age is Age
echo "<br />AGE is ".AGE;//wil print AGE is 29
echo "<br />age is ".age;//will print age is 42
?>


Go to the top of the page
 
+Quote Post
lonebyrd
post Jul 9 2006, 03:07 PM
Post #10


Premium Member
Group Icon

Group: Members
Posts: 302
Joined: 23-February 06
From: Northeastern Connecticut USA
Member No.: 11,487


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.
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   3 geektech 1,552 Yesterday, 10:28 PM
Last post by: iG-Paul
No new