Jump to content

[SOLVED] Login form possibly not functioning correctly


sanderphp

Recommended Posts

I recently updated my login page to add a register button but for some reason I can't login in anymore using any of my accounts.  I get my "wrong username or password" error.   I keep thinking that I must have changed the function of the login button or something.

 

<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="login" type="text" id="login"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td width="5%" > <input type="submit" name="login" value="login"></td>
<td width="5%" > <input type="button" value="register" onclick="window.location.href='registrationbackup.php';"></td>

</tr>

 

 

 

if(isset($_POST['login'])){
// Define $myusername and $mypassword 
$myusername=$_POST['login']; 
$mypassword=$_POST['password']; 

// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT id FROM $tbl_name WHERE login='$myusername' and password='$mypassword'";     // get the id
$result=mysql_query($sql);
if (!$result) {
   print "$sql<br>";
   print mysql_error()."<br>";
}

// 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['username'] = $myusername;
$_SESSION['password'] = $mypassword;
$_SESSION['login_id'] = mysql_result($result, 0);                                          // store the id

header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}

<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="login" type="text" id="login"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td width="5%" > <input type="submit" name="login" value="login"></td>
<td width="5%" > <input type="button" value="register" onclick="window.location.href='registrationbackup.php';"></td>

</tr>

 

first maybe change the login for each name, textfield and submit.   Since you have login for the input for text and for the submit.

 

second im not sure that

onclick="window.location.href='registrationbackup.php';"

is necessary, you can probably just use

onclick="registrationbackup.php"

  Also try print 'alert($myusername);'; see what it gives you, if its giving you what you typed and whats in your database, its you query

no. I must have changed some action.  

 

Does this look right?

 

<form name="form1" method="post" action="checklogin.php">
<td>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="login" type="text" id="login"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td width="5%" > <input type="submit" name="login" value="login"></td>
<td width="5%" > <input type="button" value="register" onclick="window.location.href='registrationbackup.php';"></td>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.