The first version was not working.. I made this simpler one, but it is not working either. It says the username or password are wrong. I also verified that it counts 0 rows with if($count==1). I am using WAMP. Thanks so much for any help.

Oh and I got the script from here and changed it slightly: (in case you need to look at their code)



// 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");

// Define $username and $mypassword 

// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";

// Mysql_num_row is counting table row
// If result matched $myusername and $mypassword, table row must be 1 row
// Register $myusername, $mypassword and redirect to file "login_success.php"
else {
echo "Wrong Username or Password";



<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<form name="form1" method="post" action="checklogin.php">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<td colspan="3"><strong>Member Login </strong></td>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="username" type="text" id="username"></td>
<td><input name="password" type="password" id="password"></td>
<td><input type="submit" name="Submit" value="Login"></td>
<td><a href='register.php'>Register?</a></td>

Recommended Answers

All 3 Replies

Member Avatar for diafol
//...other code...
if(isset($_POST['username']) && isset($_POST['password']) && !empty($_POST['username']) && !empty($_POST['password'])){

	$result=mysql_query("SELECT password FROM $tbl_name WHERE username='$user' LIMIT 1");
		$d = mysql_fetch_array('result');
		if($pass == $d['password']){
			$_SESSION['username'] = $user;
			echo "Wrong Username or Password";		
		echo "Count is 0";	

Nothing is shouting out at me, but try this bit above. ALso check that you don't have more than one entry for a username.

Thanks, I scrapped it and got it to work

Member Avatar for diafol

Care to share? Anyway, mark as solved (link below).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.