Jump to content

Problems error with Mysql setting up register form


Artmark

Recommended Posts

Hi guys I am working on adding a third party php members register and login into a clients web site but every time I try the regidter page is shows me this error message.

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'username'@'localhost' (using password: YES) in /home/cpassoc2/public_html/register-exec.php on line 15

Failed to connect to server: Access denied for user 'username'@'localhost' (using password: YES)

 

This is what i have in the config.php page.

<?php

define('DB_HOST', 'localhost');

    define('DB_USER', 'cpassoc2-memark');

    define('DB_PASSWORD', '?????????');  password replaced

    define('DB_DATABASE', 'cpassoc2-me');

?>

I have set up the my SQL within the control panel of the site, So do i need to do any thing else???, what am i missing???.

 

Mark.....

Link to comment
Share on other sites

I dont know, I click  [function.mysql-connect]:    and i get this 404 error  Not Found

 

The requested URL /function.mysql-connect was not found on this server.

 

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache mod_fcgid/2.3.6 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at cpassoc.com.au Port 80

Link to comment
Share on other sites

OK Now I have this in the register-exec.php page 

//Connect to mysql server

$link = mysql_connect("localhost","cpassoc2_memark","a69u69au2");

if(!$link) {

die('Failed to connect to server: ' . mysql_error());

}

 

//Select database

$db = mysql_select_db(DB_DATABASE);

if(!$db) {

die("Unable to select database");

}

Link to comment
Share on other sites

OK! Does it work? If not, replace DB_DATABASE with the real value (cpassoc2-me) and if it works that way, check if you have included config.php correctly.

 

EDIT: You should end up with a code like that:

 

<?php
require_once ('config.php');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Failed to connect to server: ' . mysql_error());
mysql_select_db(DB_DATABASE) or die('Unable to select database');
?>

Link to comment
Share on other sites

ok now I get (Query failed)

 

This is the config.php

<?php

define('DB_HOST', 'localhost');

    define('DB_USER', 'cpassoc2_memark');

    define('DB_PASSWORD', 'a69u69au2');

    define('DB_DATABASE', 'cpassoc2_me');

?>

 

This is the Reigister-exec.php 

 

//Connect to mysql server

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Failed to connect to server: ' . mysql_error());

mysql_select_db(DB_DATABASE) or die('Unable to select database');

 

 

//Select database

$db = mysql_select_db(DB_DATABASE) or die('Unable to select database');

 

Thats how both pages look and when i click to register i get this message now. (Query failed)

Mark.....

 

Link to comment
Share on other sites

A simple rule of thumb when asking help: Instead of telling us only what error you're getting, show us the line of code too and possibly a few lines before and after that. How can one help without seeing the actual code? Show us the query...

Link to comment
Share on other sites

 

This is the reigister-exec.php page.

<?php
//Start session
session_start();

//Include database connection details
require_once('config.php');

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Failed to connect to server: ' . mysql_error());
mysql_select_db(DB_DATABASE) or die('Unable to select database');


//Select database
$db = mysql_select_db(DB_DATABASE) or die('Unable to select database');


//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
	$str = @trim($str);
	if(get_magic_quotes_gpc()) {
		$str = stripslashes($str);
	}
	return mysql_real_escape_string($str);
}

//Sanitize the POST values
$fname = clean($_POST['fname']);
$lname = clean($_POST['lname']);
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$cpassword = clean($_POST['cpassword']);

//Input Validations
if($fname == '') {
	$errmsg_arr[] = 'First name missing';
	$errflag = true;
}
if($lname == '') {
	$errmsg_arr[] = 'Last name missing';
	$errflag = true;
}
if($login == '') {
	$errmsg_arr[] = 'Login ID missing';
	$errflag = true;
}
if($password == '') {

 

This is the config.php page.

 

<?php
define('DB_HOST', 'localhost');
    define('DB_USER', 'cpassoc2_memark');
    define('DB_PASSWORD', 'a69u69au2');
    define('DB_DATABASE', 'cpassoc2_me');
?>

Link to comment
Share on other sites

This is the whole page register-exec.php.

 <?php
//Start session
session_start();

//Include database connection details
require_once('config.php');

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Failed to connect to server: ' . mysql_error());
mysql_select_db(DB_DATABASE) or die('Unable to select database');


//Select database
$db = mysql_select_db(DB_DATABASE) or die('Unable to select database');


//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
	$str = @trim($str);
	if(get_magic_quotes_gpc()) {
		$str = stripslashes($str);
	}
	return mysql_real_escape_string($str);
}

//Sanitize the POST values
$fname = clean($_POST['fname']);
$lname = clean($_POST['lname']);
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$cpassword = clean($_POST['cpassword']);

//Input Validations
if($fname == '') {
	$errmsg_arr[] = 'First name missing';
	$errflag = true;
}
if($lname == '') {
	$errmsg_arr[] = 'Last name missing';
	$errflag = true;
}
if($login == '') {
	$errmsg_arr[] = 'Login ID missing';
	$errflag = true;
}
if($password == '') {
	$errmsg_arr[] = 'Password missing';
	$errflag = true;
}
if($cpassword == '') {
	$errmsg_arr[] = 'Confirm password missing';
	$errflag = true;
}
if( strcmp($password, $cpassword) != 0 ) {
	$errmsg_arr[] = 'Passwords do not match';
	$errflag = true;
}

//Check for duplicate login ID
if($login != '') {
	$qry = "SELECT * FROM members WHERE login='$login'";
	$result = mysql_query($qry);
	if($result) {
		if(mysql_num_rows($result) > 0) {
			$errmsg_arr[] = 'Login ID already in use';
			$errflag = true;
		}
		@mysql_free_result($result);
	}
	else {
		die("Query failed");
	}
}

//If there are input validations, redirect back to the registration form
if($errflag) {
	$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
	session_write_close();
	header("location: register-form.php");
	exit();
}

//Create INSERT query
$qry = "INSERT INTO members(firstname, lastname, login, passwd) VALUES('$fname','$lname','$login','".md5($_POST['password'])."')";
$result = @mysql_query($qry);

//Check whether the query was successful or not
if($result) {
	header("location: register-success.php");
	exit();
}else {
	die("Query failed");
}
?>

Link to comment
Share on other sites

This is the actual blank form code ,Now I want to place the code withing the website html pages so its not just a blank sign in page.

 

http://www.cpassoc.com.au/PHP-Login.zip

 

If some one has time could you please configure this for me to add to the clients website as they want a members loging and page only to be view by members.

I dont know if that is the best form code but it look ok to me for what i want.

But if some on has something better and easyer out there I would love to here from them.

you can email me here:    mark at artmarkdesigns.com

 

I want a register page ,

a log in page ,

a confirmation page

and pages hidden unless you are logged in as a member.

and what ever other pages i need.

 

 

My data base details.

<?php

define('DB_HOST', 'localhost');

    define('DB_USER', 'cpassoc2_memark');

    define('DB_PASSWORD', 'a69u69au2');

    define('DB_DATABASE', 'cpassoc2_me');

?>

 

Thanks, Mark.....

Link to comment
Share on other sites

GGGGRRRRRR

PHP is for the experts or nerds.

Its doing my head in. GGGGGRRRRRRRRR  AAAAHHHHHHGGGGG.

Sorry for making a noise but I am so frustrated, My clients want this login but I just cant do it and I dont want ot use Joomla or server side stuff like that ,its even harder to get your head around.

 

Mark........

Link to comment
Share on other sites

So, did the suggested use of mysql_error() in the die(...) statement, that Pikachu2000 posted, produce a mysql error message?

 

And, there are two different queries that could have been producing the original "Query failed" message and you would need to alter the code for both of them to insure that you get an mysql error to be reported for the one(s) that fail.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.