Can anyone see a reason why this code would continually return “Wrong Username or Password”? I am using it locally on a windows XP pc using xampp for my php and mysql. The code was taken, unchanged, from my webserver where it actually functions as it should. Could this be because it’s on an XP machine? I also exported the database from my actual server and it looks fin in phpmyadmin. The script which calls this is below also incase that helps.
checklogin.php
[code=php]<?php
include(“misc.inc”);
$tbl_name = ‘members’;
// Connect to server and select databse.
mysql_connect(“$host”, “$user”, “$password”)or die(“cannot connect”);
mysql_select_db(“$database”)or die(“cannot select DB”);
$mypassword = sha1($mypassword);
$myusername = addslashes($myusername);
$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){
$_SESSION[‘myusername’] = stripslashes($_POST[‘myusername’]);
$_SESSION[‘mypassword’] = $_POST[‘mypassword’];
if(isset($_POST[‘remember’])){
setcookie(“cookname”, $_SESSION[‘myusername’], time()+60*60*24*100, “/”);
setcookie(“cookpass”, $_SESSION[‘mypassword’], time()+60*60*24*100, “/”);
}
// Register $myusername and redirect to file “login_success.php”
session_register(“myusername”);
header(“location:index.php”);
} else {
echo “Wrong Username or Password”;
}
?>
login.php
[code=php]<?php
session_start();
echo “<p class=’login’>n”;
$myusername = stripslashes($myusername);
if (!session_is_registered(“myusername”)) {
echo “<table>n
<form action=’checklogin.php’ method=’post’ name=’authentication’>n
<tr>n
<td><span class=’inputlabel’>Username:</span></td><td><input class=’input’ type=’text’ size=’25’ name=’myusername’ /></td>n
</tr>n
<tr>n
<td><span class=’inputlabel’>Password:</span></td><td><input class=’input’ type=’password’ size=’25’ name=’mypassword’ /></td>n
</tr>n
<tr>n
<td><span class=’inputlabel’>Remember me?:</span></td><td><input type=’checkbox’ name=’remember’>(requires cookies)</td>n
</tr>n
<tr>n
<td> </td><td><input class=’input’ type=’submit’ name=’submit’ value=’Log in’ /></td>n
</tr>n
</form>n
</table><br >n
<a href=’register.php’>Register</a>”;
} else {
$myusername = stripslashes($myusername);
echo “Welcome $myusername</p>n
<p style=’text-align:right; margin-right: 30px’>n
<a href=’userdetails.php’>My Details |</a>n
<a href=’logout.php’>Log out |</a>n”;
} ?>
<a href=’userlist.php’>Userlist |</a>
</p>