Jump to content

Mysql Logging In


Imoddedu

Recommended Posts

I got this error from the registration page I am working on. Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'suitefou'@'localhost' (using password: NO) in /home1/suitefou/public_html/opxtest/web/stats.php on line 19Error connecting to mysqlPHP from register.php

<?phprequire_once('config.php');	if($_POST) {		$password = $_POST['password'];		$confirm = $_POST['confirm'];			if($password != $confirm) { ?><span style='color:red'>Error: Passwords do not match!</span>		<?php	} else {			$conn = mysql_connect($dbhost,$dbuser,$dbpass)				or die ('Error connecting to mysql');			mysql_select_db($dbname);			$query = sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s')",				mysql_real_escape_string($_POST['username']));			$result = mysql_query($query);			list($count) = mysql_fetch_row($result);			if($count >= 1) { ?><span style='color:red'>Error: that username is taken.</span><?php		} else {				$email = $_POST['email'];				$query = sprintf("INSERT INTO users(username,password,email) VALUES ('%s','%s','%s');",					mysql_real_escape_string($_POST['username']),					mysql_real_escape_string(md5($password)),					mysql_real_escape_string($email));				mysql_query($query);				$userID = mysql_insert_id($conn);				require_once 'stats.php';				setStat('inf',$userID,'0');				setStat('air',$userID,'0');							setStat('sea',$userID,'0');				setStat('vehi',$userID,'0');				setStat('tech',$userID,'0');				setStat('sup',$userID,'0');				setStat('mora',$userID,'100');				$to = $email;				$subject = 'bleh';				$message = "<p>bleh</p><p><a href='bleh/confirm.php?email=$email'>Click to verify</a></p>";				$headers = 'From: bleh@bleh.com' . "\r\n" .							'Content-type: text/html; charset=iso-8859-1' . "\r\n";				mail($to,$subject,$message,$headers);			?><span style='color:green'>Congratulations, you've registered successfully! A confirmation e-mail has been sent to the address you submitted.</span><?php			}			}	}?>

PHP from Stats.php

<?php function getStat($statName,$userID) {	require_once('config.php');	$conn = mysql_connect($dbhost,$dbuser,$dbpass)		or die ('Error connecting to mysql:');	mysql_select_db($dbname);	createIfNotExists($statName,$userID);	$query = sprintf("SELECT value FROM user_stats WHERE stat_id = (SELECT id FROM stats WHERE display_name = '%s' OR short_name = '%s') AND user_id = '%s'",		mysql_real_escape_string($statName),		mysql_real_escape_string($statName),		mysql_real_escape_string($userID));	$result = mysql_query($query);	list($value) = mysql_fetch_row($result);	return $value;		}function setStat($statName,$userID,$value) {	require_once('config.php');	$conn = mysql_connect($dbhost,$dbuser,$dbpass)		or die ('Error connecting to mysql');	mysql_select_db($dbname);	createIfNotExists($statName,$userID);	$query = sprintf("UPDATE user_stats SET value = '%s' WHERE stat_id = (SELECT id FROM stats WHERE display_name = '%s' OR short_name = '%s') AND user_id = '%s'",		mysql_real_escape_string($value),		mysql_real_escape_string($statName),		mysql_real_escape_string($statName),		mysql_real_escape_string($userID));	$result = mysql_query($query);} function createIfNotExists($statName,$userID) {	require_once('config.php');	$conn = mysql_connect($dbhost,$dbuser,$dbpass)		or die ('Error connecting to mysql:');	mysql_select_db($dbname);	$query = sprintf("SELECT count(value) FROM user_stats WHERE stat_id = (SELECT id FROM stats WHERE display_name = '%s' OR short_name = '%s') AND user_id = '%s'",		mysql_real_escape_string($statName),		mysql_real_escape_string($statName),		mysql_real_escape_string($userID));	$result = mysql_query($query);	list($count) = mysql_fetch_row($result);	if($count == 0) {		// the stat doesn't exist; insert it into the database		$query = sprintf("INSERT INTO user_stats(stat_id,user_id,value) VALUES ((SELECT id FROM stats WHERE display_name = '%s' OR short_name = '%s'),'%s','%s')",		mysql_real_escape_string($statName),		mysql_real_escape_string($statName),		mysql_real_escape_string($userID),		'0');		mysql_query($query);	}	} ?>

Any suggestions?

Link to comment
Share on other sites

What's in your config.php file?Your database is not connecting. Are you sure you are using the right information when connecting to the database? Specifically your variables.

$conn = mysql_connect($dbhost,$dbuser,$dbpass);mysql_select_db($dbname);

Link to comment
Share on other sites

What's in your config.php file?Your database is not connecting. Are you sure you are using the right information when connecting to the database? Specifically your variables.
$conn = mysql_connect($dbhost,$dbuser,$dbpass);mysql_select_db($dbname);

Yea I already tried looking into that and nothing is wrong with the file.
Link to comment
Share on other sites

Yea I already tried looking into that and nothing is wrong with the file.
Are you connecting to the correct database? Does it even exist?What's line 19?Edit: When I try to connect to a online database through my localhost I get a similar error. If you are in a localhost, connect to your local database instead of your online one.
Link to comment
Share on other sites

Are you connecting to the correct database? Does it even exist?What's line 19?Edit: When I try to connect to a online database through my localhost I get a similar error. If you are in a localhost, connect to your local database instead of your online one.
What do you mean by your last sentence? Yes, the DB exists. I'm in CPanel's phpMyAdmin right now looking at it.Line 19 is bolded in this function.
function setStat($statName,$userID,$value) {	require_once('config.php');	[b]$conn = mysql_connect($dbhost,$dbuser,$dbpass)[/b]		or die ('Error connecting to mysql');	mysql_select_db($dbname);	createIfNotExists($statName,$userID);	$query = sprintf("UPDATE user_stats SET value = '%s' WHERE stat_id = (SELECT id FROM stats WHERE display_name = '%s' OR short_name = '%s') AND user_id = '%s'",		mysql_real_escape_string($value),		mysql_real_escape_string($statName),		mysql_real_escape_string($statName),		mysql_real_escape_string($userID));	$result = mysql_query($query);}

Link to comment
Share on other sites

On shared hosts using Cpanel, it sometimes requires special Database naming conventions.Ie: Username_dbname to identify the DB to be opened.username + underscore + dbname works on my hosting.

Link to comment
Share on other sites

On shared hosts using Cpanel, it sometimes requires special Database naming conventions.Ie: Username_dbname to identify the DB to be opened.username + underscore + dbname works on my hosting.
Yea I have that as well.
Link to comment
Share on other sites

Well, obviously it either can't find the database server, or your username and password are wrong. If you know your username and password are right, then it can't find the database server. cPanel will give you the exact hostname to use to connect to the database, it will even give you the exact PHP code needed. With MySQL 4 it's probably "localhost" and with MySQL 5 it's probably a socket connection. Check in cPanel to see what it says. If you can't find it, send your host an email and ask them.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...