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";
}

Link to comment
Share on other sites

<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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.