Diggers34 Posted February 23, 2007 Share Posted February 23, 2007 I am trying to set up a longin for my website. When I enter my username and password and hit enter I get the following message. cannot connect Here is my page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $host="127.0.0.1"; // Host name $username="root"; // Mysql username $password="ireland"; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // 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"); // username and password sent from signup form $myusername=$_POST['myusername']; $mypassword=$_POST['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 "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> </body> </html> any ideas. My set up is I am testing on my providers site http://www.siesta.cat/login2/main_login.php. Am I missing something? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/39772-cant-connect-to-mysql-db/ Share on other sites More sharing options...
paul2463 Posted February 23, 2007 Share Posted February 23, 2007 your error is saying it cannot conect to the database with the perameters you have given it as you have already set variables with the strings required to connect to the database try this <?php mysql_connect($host, $username, $password)or die("cannot connect"); ?> EDIT: if that doesnt work check that the login details are correct too Quote Link to comment https://forums.phpfreaks.com/topic/39772-cant-connect-to-mysql-db/#findComment-192047 Share on other sites More sharing options...
Diggers34 Posted February 23, 2007 Author Share Posted February 23, 2007 How can I check if the log in details are correct? Quote Link to comment https://forums.phpfreaks.com/topic/39772-cant-connect-to-mysql-db/#findComment-192119 Share on other sites More sharing options...
paul2463 Posted February 23, 2007 Share Posted February 23, 2007 try this and tell us what the error says <?php mysql_connect($host, $username, $password) or die ('Could not connect: ' . mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/39772-cant-connect-to-mysql-db/#findComment-192251 Share on other sites More sharing options...
weknowtheworld Posted February 23, 2007 Share Posted February 23, 2007 Try this : $host="localhost"; // Host name Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/39772-cant-connect-to-mysql-db/#findComment-192308 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.