I have problem with my connection. This is a shared server and I have use SSH to check my database and my tables. I use the same credential to access them thru the web. However it gives me error. I check for any typo, but they are correct and my sql access and my database don't have username or password. So I only have one user and pass for my host. I have created my tabales and uploaded my pages to the same database with same username and password.
# Can this problem be the server problem? so whoever established did not configure it correctly?? #
this is the error:
Warning: mysql_connect(): Access denied for user 'cop...'@'139.62.63....' (using password: YES) in /home/cop.../homepage/login.php on line 10 Could not connect to database
and here is my code, is there anything that I can do? can you think of anything else, but typo ?
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
if(!($sqlCon= mysql_connect("139.62.63...","cop..","abcdef")))
die( "<p>Could not connect to database</p>" );
if (! ($dbCon = mysql_select_db("cop..", $sqlCon)))
die( "<p>Could not open database</p>" );
// username and password sent from form
$myusername=$_POST['email'];
$mypassword=$_POST['password'];
$submit=$_POST['submit'];
echo'<form name="Login" method="post">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>';
if($submit) {
// 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 "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
mysql_close($sqlCon);
}
?>
</body>
</html>
Incorrect password to connect to MySQL. Check your configuration. It's funny that you are creating a login form to verify username password when in fact your application cannot connect to the database.