Artmark Posted April 25, 2011 Share Posted April 25, 2011 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..... Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/ Share on other sites More sharing options...
Fadion Posted April 25, 2011 Share Posted April 25, 2011 What is the mysql_connect() code? Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206140 Share on other sites More sharing options...
Artmark Posted April 25, 2011 Author Share Posted April 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206142 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 The error message tells you which line of which file caused the error. That's where you'll find it. Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206143 Share on other sites More sharing options...
Artmark Posted April 25, 2011 Author Share Posted April 25, 2011 Thanks I relised I had not put in the correct mysql details in line 15. Now I get this ( Unable to select database ) After Registering. Mark..... Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206149 Share on other sites More sharing options...
Fadion Posted April 25, 2011 Share Posted April 25, 2011 After the mysql_connect() function, place: mysql_select_db(DB_DATABASE); Supposing that 'cpassoc2-me' exists as a database, it should work. Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206154 Share on other sites More sharing options...
Artmark Posted April 25, 2011 Author Share Posted April 25, 2011 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"); } Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206156 Share on other sites More sharing options...
Fadion Posted April 25, 2011 Share Posted April 25, 2011 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206160 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 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..... Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206171 Share on other sites More sharing options...
Pikachu2000 Posted April 26, 2011 Share Posted April 26, 2011 You're actually getting "Query Failed"? If that's the error message, your connection is succeeding, but there's a problem with the query. Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206174 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 You're actually getting "Query Failed"? If that's the error message, your connection is succeeding, but there's a problem with the query. How do i fix the Query in what page. Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206177 Share on other sites More sharing options...
Fadion Posted April 26, 2011 Share Posted April 26, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206179 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 Sorry i am new to this php, and asking for help. Mark..... Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206181 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 I have looked at all the pages and i can not find where the query is coming from to show you any code. mark..... Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206187 Share on other sites More sharing options...
Pikachu2000 Posted April 26, 2011 Share Posted April 26, 2011 Do a search in your editor for "Query failed". Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206191 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 I am using Adobe Dreamweaver CS5 and new to searching falts. Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206193 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206197 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206208 Share on other sites More sharing options...
Pikachu2000 Posted April 26, 2011 Share Posted April 26, 2011 Change this: }else { die("Query failed"); } To this: }else { die("<br>Query: $qry<br>Failed with error: " .mysql_error() ); } And post the error it returns when you run the script. Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206210 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 This is the login page http://cpassoc.com.au/register-form.php. Maybe I placed the code wrong or some thing. I just dont know what the heck i am doing. Mark.. Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206222 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 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..... Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206230 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 Thanks for the support. I'll tell my client I cant do what they ask for a members log in ,its out of my field, thanks for the supports. Mark...... Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206249 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 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........ Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206289 Share on other sites More sharing options...
PFMaBiSmAd Posted April 26, 2011 Share Posted April 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206293 Share on other sites More sharing options...
Artmark Posted April 26, 2011 Author Share Posted April 26, 2011 it did not work Quote Link to comment https://forums.phpfreaks.com/topic/234714-problems-error-with-mysql-setting-up-register-form/#findComment-1206300 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.