Sianna Posted February 11, 2010 Share Posted February 11, 2010 so, i am extremely new to php so forgive my lack of knowledge with this! i am trying to get a login php script to work, but can not figure it out for the life of me. when i go to login(with any login name/password), i get this error: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user_here'@'gator375.hostgator.com' (using password: YES) in /home/ladadada/public_html/sitename.com/route/check.php on line 9 cannot connect i had created the database, everything from a tutorial so it is possible that i screwed some stuff up, but, this appears to be something wrong with the script not necessarily the database ?php $host="host_name_here"; // Host name $username="username_here"; // Mysql username $password="password_here"; // Mysql password $db_name="DB_name_here"; // Database name $tbl_name="TB_name_here"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); that is everything up to line 9, all the info filled out but in this preview just showing where i had put the info. - i guess one confusion would be the host name! i wasn't sure if it was the IP or something like 'sitehere.com'. if anyone could tell me exactly how that information should be filled out it would be very appreciated, or, if i'm doing it completely wrong! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/191725-login-php/ Share on other sites More sharing options...
yozyk Posted February 11, 2010 Share Posted February 11, 2010 Try $host="localhost"; and probably you need to set Privileges to DB for DB-user Quote Link to comment https://forums.phpfreaks.com/topic/191725-login-php/#findComment-1010555 Share on other sites More sharing options...
Deoctor Posted February 11, 2010 Share Posted February 11, 2010 Hai change this code ?php $host="host_name_here"; // Host name $username="username_here"; // Mysql username $password="password_here"; // Mysql password $db_name="DB_name_here"; // Database name $tbl_name="TB_name_here"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); to some thing like this <?php $host="localhost"; // Host name $username="username_here"; // Mysql username $password="password_here"; // Mysql password $db_name="DB_name_here"; // Database name $tbl_name="TB_name_here"; // Table name // Connect to server and select databse. mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db($db_name)or die("cannot select DB"); are u sure is this file which is giving a problem... can u copy the check.php file Quote Link to comment https://forums.phpfreaks.com/topic/191725-login-php/#findComment-1010571 Share on other sites More sharing options...
Sianna Posted February 11, 2010 Author Share Posted February 11, 2010 sure. here is the entire check.php file <?php $host="host_name_here"; // Host name $username="username_here"; // Mysql username $password="password_here"; // Mysql password $db_name="DB_name_here"; // Database name $tbl_name="TB_name_here"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "loggedin.php" session_register("myusername"); session_register("mypassword"); header("location:loggedin.php"); } else { echo "Wrong Username or Password"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/191725-login-php/#findComment-1010856 Share on other sites More sharing options...
Deoctor Posted February 12, 2010 Share Posted February 12, 2010 mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_select_db("$db_name")or die("cannot select DB"); in this remove the double qoutes from mysql_connect("$host", "$username", "$password") mysql_select_db("$db_name") and make it some thing like this mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db($db_name)or die("cannot select DB"); Quote Link to comment https://forums.phpfreaks.com/topic/191725-login-php/#findComment-1011196 Share on other sites More sharing options...
Sianna Posted February 13, 2010 Author Share Posted February 13, 2010 just did what you suggested and i seem to be getting the same error. i also changed the host name to localhost as suggested by a previous poster. not really sure why this isn't working, maybe the tutorial and all its information was oudated . that being said, anyone know of a fluent login tutorial that does work? Quote Link to comment https://forums.phpfreaks.com/topic/191725-login-php/#findComment-1011638 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2010 Share Posted February 13, 2010 The screen where you created your database, the database user/password, and assigned that user/password permission to access the database should have also displayed the correct hostname or IP address to use for accessing the correct database server for your hosting account (most larger web hosts have multiple database servers and assign your account a specific one to use.) Edit: also many web hosts require that your database name and username be a combination of your web hosting user name - see this relevant link from the hostgator FAQ section - http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database Quote Link to comment https://forums.phpfreaks.com/topic/191725-login-php/#findComment-1011639 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.