php - 登录脚本未按要求工作

标签 php mysql authentication

我是 php 的新手,并尝试开发一个登录脚本,但是当我输入值时它不起作用。我什至找不到错误,因为当我点击提交时,它只会刷新页面

这是我的代码

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

谁能帮帮我,我花了很多时间都没有成功

这是html代码

<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>

最佳答案

好的,你有一个带有文件名的 echo 语句:

   echo "myaccount.php";

首先,你确定那是你想要做的吗?我相信这会回显字符串“myaccount.php”。我相信你会想要包括“myaccount.php”

其次,您在 javascript 中引用了表单字段“user_name”,但您尝试访问的字段名称名为“email”。这也可能是问题的一部分。

关于php - 登录脚本未按要求工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13400971/

相关文章:

java - Spring REST 应用程序中身份验证的最佳方式

android - 文本属性下方的 EditText 下划线

php - Jquery 从弹出窗口中选择项目并回发给父级

php - 将 UTF-8 字符作为 Ascii 写入文件

php - Woocommerce/Wordpress - 添加按钮到管理面板上的订单/产品页面

MySQLi 多查询代码问题

php - Symfony2 响应内容必须是字符串或对象实现 __toString(), "boolean"given

java - 切换表格列以输入数据

java - SQLException "No value specified for parameter 3"

ruby-on-rails - authenticate_with_http_token 评估为 nil