Page 1 of 1

Login Troubleshoot

Posted: Sun Apr 05, 2009 8:31 am
by Seraphimk
I have this login script and it doesnt work ive gone through it and i can't see anything wrong with it can people just look through it and tell me if ive got something wrong.

Code: Select all

 
<?php 
include 'dbc.php';
 
$user_email = mysql_real_escape_string($_POST['email']);
 
if ($_POST['Submit']=='Login')
{
$user_password = ($_POST['password']);
$sql = "SELECT  user_id,user_email,user_password FROM tblUsers WHERE 
            user_email = '$user_email' AND 
            user_password = '$user_password' AND user_status='5'"; 
            
$result = mysql_query($sql) or die (mysql_error()); 
$num = mysql_num_rows($result);
 
    if ( $num != 0 ) { 
 
        // A matching row was found - the user is authenticated. 
       session_start(); 
       list($user_id,$user_email) = mysql_fetch_row($result);
        // this sets variables in the session 
        $_SESSION['user']= $user_email;  
        
            
        if (isset($_GET['ret']) && !empty($_GET['ret']))
        {
        header("Location: $_GET[ret]");
        } else
        {
        header("Location: index.php");
        }
        //echo "Logged in...";
        exit();
    } 
 
header("Location: login.php?msg=Invalid Login");
//echo "Error:";
exit();     
}
 
?>
 
<link href="styles.css" rel="stylesheet" type="text/css">
 
<?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>
 
 
<p>&nbsp;</p><table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td bgcolor="#d5e8f9" class="mnuheader" >
<div align="center"><font size="5"><strong>Login 
        Members</strong></font></div></td>
  </tr>
  <tr> 
    <td bgcolor="#e5ecf9" class="mnubody"><form name="form1" method="post" action="">
        <p>&nbsp;</p>
        <p align="center">Your Email 
          <input name="email" type="text" id="email">
        </p>
        <p align="center"> Password: 
          <input name="pwd" type="password" id="password">
        </p>
        <p align="center"> 
          <input type="submit" name="Submit" value="Login">
        </p>
        <p align="center"><a href="register.php">Register</a> | <a href="forgot.php">Forgot</a></p>
      </form></td>
  </tr>
</table>
 
cheers!

Re: Login Troubleshoot

Posted: Sun Apr 05, 2009 10:40 am
by requinix
If you expect us to look at your code just in case something is wrong then think again.

Now, if you have a problem with it and you can't see where, that's different...

Re: Login Troubleshoot

Posted: Sun Apr 05, 2009 10:49 am
by Seraphimk
tasairis wrote:If you expect us to look at your code just in case something is wrong then think again.

Now, if you have a problem with it and you can't see where, that's different...
thats what i was saying theres a problem with it and i cant find it :/

Re: Login Troubleshoot

Posted: Sun Apr 05, 2009 12:02 pm
by requinix
Seraphimk wrote:thats what i was saying theres a problem with it and i cant find it :/
So are we supposed to look for every possible problem or do you have anything to suggest?

Re: Login Troubleshoot

Posted: Sun Apr 05, 2009 12:17 pm
by Seraphimk
tasairis wrote:
Seraphimk wrote:thats what i was saying theres a problem with it and i cant find it :/
So are we supposed to look for every possible problem or do you have anything to suggest?
well when i test it, it comes up with login invalid and well im not sure check if the query is right the password in the database isnt encrypted i dunnu wat to look for if i did i wouldnt be in this forum askin you all im askin is for a little help

Re: Login Troubleshoot

Posted: Sun Apr 05, 2009 12:28 pm
by tech603

Code: Select all

AND user_status='5'
Is that necessary for the user log in? Do all users have the same status? Also another suggestion would be to switch your num_rows check,

Code: Select all

 
 
From this
if ( $num != 0 ) {
 
to this 
 
if ( $num == 1 ) {
 
 
Both the above should technically do the same thing, but just want to make sure that the result is not turning up null instead of 0. If those suggestions do not work, then test your query on your mysql database to ensure the query itself is working.

Hope this helps

Re: Login Troubleshoot

Posted: Sun Apr 05, 2009 12:43 pm
by Seraphimk
tech603 wrote:

Code: Select all

AND user_status='5'
Is that necessary for the user log in? Do all users have the same status? Also another suggestion would be to switch your num_rows check,

Code: Select all

 
 
From this
if ( $num != 0 ) {
 
to this 
 
if ( $num == 1 ) {
 
 

Thanks ill test it when i get back i have to go out now thanks for the help though
and the user_status is need because its a paid membership so when the member has paid his status changes to 5 so they can log in.
Both the above should technically do the same thing, but just want to make sure that the result is not turning up null instead of 0. If those suggestions do not work, then test your query on your mysql database to ensure the query itself is working.

Hope this helps