-3

Possible Duplicate:
Login script not working as required

Here is a new question as reuested alongwith my code

Here is my code

<?php include "../utilities/config.php"; 

foreach($_GET as $key=>$value)
{
${$key} = trim($value);
}
$error = '';
if($checking_member_availability == 'yes'){
if(empty($user_name)){
    $error .= "Please enter user name.<br />";
}
if(empty($password)){
    $error .= "Please enter password.<br />";
}
if(empty($error)){
        $sql = "select * from `".SITE_TABLE_PREFIX."user` where     email='".$user_name."' and pwd='".$password."'";
        $resultUser  = mysql_query($sql) or die(mysql_error().$sql);
        if(mysql_num_rows($resultUser)>0){
        $rowUser  = mysql_fetch_array($resultUser);
        $error .= '';
        $_SESSION['email']=$user_name;
        }else{
        $error .= "Please check Email and Password.";
    }
}

if(empty($error)){

    echo "myaccount.php";
}
else{
    echo "<font color='#A01D49'>$error</font>";
}
}
?>

Please can anyone help me I have spent a lot of time without success

Here is the html code

<script type="text/javascript" language="javascript">
function validation()
{
var password = trim(document.form1.password.value);
var user_name = trim(document.form1.user_name.value);
var type = trim(document.form1.type.value);
http.open("GET", "processor.php?checking_member_availability=yes&password="+
                    escape(password)+"&user_name="+   escape(user_name)+"&type=" + escape(type)  , true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
return false;
}
</script>
</head>
<table width="241" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><table width="100%" border="0" cellspacing="0" cellpadding="0" <?php   if($_SESSION['user_id']!=''){?> style="display:none;"<?php }?>>
              <tr>
                <td align="left" valign="top" class="loginBg">
                    <img src="img/logintxt.jpg" alt = '' width='100' height='29' border='0'>
                </td>
              </tr>
              <tr>
                <td align="left" valign="top" class="login"><form name="form1" id="form1" action="" method="post" onSubmit="return validation();">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                     <tr><td colspan="3"><span id="user"></span></td></tr>
                      <tr>
                        <td align="left" valign="middle" class="height"><label class="boldtxt">Email:</label></td>
                        <td align="left" valign="middle" class="heightMid"><input type="text" name="email" id="email" />
                        </td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle"><label class="boldtxt">Password:</label></td>
                        <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td align="left" valign="top"><input type="password" name="password" id='password' class="loginfld" />
                              </td>
                              <td align="left" valign="middle"><input type="image" src="img/submit.jpg" class="submit" onClick="return validation();" />
                              </td>
                            </tr>
                          </table></td>
                      </tr>
                      <tr>
                        <td align="left" valign="top">&nbsp;</td>
                        <td align="left" valign="top"><a href="forget_password.php" class="normalTxt">Forgot your password?</a><br />
                        </td>
                      </tr>
                    </table>
                  </form></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td align="left" valign="top">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td align="left" valign="top"><a href="provider_registration.php"><img src="images/applybut.jpg" alt="" border="0" class="apply" /></a></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top">
                      <?=$value?>
                      </td>
                    </tr>
                    <tr>
                        <td align="left" valign="top">&nbsp;</td>
                    </tr>
                    <tr>
                      <td align="left" valign="top">&nbsp;</td>
                    </tr>
                </table>
          </td>
        </tr>
      </table>

Can anyone now help me resolve this issue pls

Community
  • 1
  • 1
  • 1
    What is the problem you are facing? – Avin Varghese Nov 15 '12 at 16:25
  • 2
    Solve *what*? Please specify the exact problem you discovered. -- Also note that you should escape database input, should not localize random variable names with `${$key} = trim($value);` (that's register_globals right there) as it may overwrite existing vars. – mario Nov 15 '12 at 16:25
  • 3
    Didn't you just ask this same question like 5 minutes ago? – Sammitch Nov 15 '12 at 16:25
  • yyes it is duplicate of login script not working as required because grim commented me to open a new question with the same details so that he cn help me and other users can also get benefit of that – rajan mehta Nov 15 '12 at 16:47
  • So pls stop reducing ,y reputation – rajan mehta Nov 15 '12 at 16:48

1 Answers1

0

Can you include the original context of your problem? What is the error / incorrect behavior? Is this hosted somewhere to test?

From what I can tell it is not redirecting on successful login based on

if(empty($error)){
    echo "myaccount.php";
}

This line only outputs "myaccount.php". I believe if you change your empty($error) check to include the redirect, it should work.

if(empty($error)) {
    $sql = "select * from `".SITE_TABLE_PREFIX."user` where     email='".$user_name."' and pwd='".$password."'";
        $resultUser  = mysql_query($sql) or die(mysql_error().$sql);
        if(mysql_num_rows($resultUser) > 0) {
        $rowUser  = mysql_fetch_array($resultUser);
        $error .= '';
        $_SESSION['email'] = $user_name;

        /* Redirect user if successful login */
        header('Location: myaccount.php');
    } else {
        $error .= "Please check Email and Password.";
}
Don Boots
  • 2,028
  • 2
  • 18
  • 26
  • Thanks for answering. My main problem is like I have written thsi php and html code after lookin at few basic php login tutorials. i am new and dont know how does it work. Right now it is on test server here is the link : http://www.speculot.com.php53-22.ord1-1.websitetestlink.com/login.php Some user on the previous question commneted me to open a new same question and he will help me so I did that and now there is no one to help. – rajan mehta Nov 15 '12 at 16:45
  • For starters, if you check out your javascript error log and/or browser console, you can see that when you submit you are getting javascript errors. trim() is not a valid javascript function. If you remove those function calls and re-upload, you may get different results. So make `trim(document.form1.password.value)` just `document.form1.password.value`, for now. – Don Boots Nov 15 '12 at 21:15