0

我在一个培训和安置网站上工作,我有一个小问题,但我被卡住了..希望我能得到帮助..登录页面的代码如下......这是 tpr.php

<?php require_once("includes/tsession.php");?>
<?php require_once("includes/connection.php");?>
<?php require_once("includes/functions.php");?>
<?php

    if (isset($_POST['submit'])) 
    {
        $branch = trim(mysql_prep($_POST['branch']));
        $tprid = trim(mysql_prep($_POST['tprid']));
        $password = trim(mysql_prep($_POST['password']));

        $hashed_password = sha1($password);

        $query = "SELECT t.userID FROM tpr t,branch b WHERE    b.branch_ID=t.branch_id AND b.branch_name='{$branch}'     
        AND t.password = '{$hashed_password}' AND t.userID='{$tprid}' limit 1" or die(mysql_error());    
            $result_set = mysql_query($query);
            confirm_query($result_set);


            if (mysql_num_rows($result_set) == 1 ) {
                // username/password authenticated
                // and only 1 match

                echo "<script type='text/javascript'>alert('Username    /password/branch combination correct.');</script>";
                $found_user = mysql_fetch_array($result_set);



                $_SESSION['sessionid2']=$found_user['Userid'];
                redirect_to("tpr.php");
            } else {
                // username/password combo was not found in the database

                echo "<script type='text/javascript'>alert('Username/password/branch combination incorrect.');</script>";    
                $message = "Username/password/branch combination     incorrect.<br />    
            }
    }
    else{
    if(isset($_GET['logout']) && ($_GET['logout']==1) )
    {
        $message= "You are now logged out";
    }
    echo "<script type='text/javascript'>alert('out of submit');</script>";

    $tpoid="";
    $password="";
    }
?>
<?php include("includes/header.php"); ?>
<div id="main">
    <table id="structure">
    <tr>
    <td id="navigation">
    <a href="content.php">Return to Home</a>
    </td>
    <td id="page">
    <h2>Login</h2>
    <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
    <form action="tpr_login.php" method="post">
    <table id="inner" cellpadding="10">
    <tr>
    <td>Select Branch</td>
    <td>

 <?php

 $con = mysql_connect("localhost","TestUserFirst","TestUserFirst");
 $db = mysql_select_db("student",$con);
 $get=mysql_query("SELECT branch_name FROM branch ORDER BY branch_ID ASC");
$option = '';
 while($row = mysql_fetch_assoc($get))
{
  $option .= '<option value =      "'.$row['branch_name'].'">'.$row['branch_name'].'</option>';
}
?>
 <select name="branch" id="branch"> 
<?php echo $option; ?>
</select>
</td>
</tr>
    <tr>
    <td>TPRId</td>
    <td><input type=text name="tprid" id="tprid" value=""></td>
    </tr><tr>
    <td>Password</td>
    <td><input type=password name="password" id="password" value=""></td>
    </tr><tr>
    <td></td>
    <td><input type="submit" name="submit" value="Login"></td>
    </tr>
    </table>
    </td>
    </tr>
    </form>

    </table>
</div>
<?php require("includes/footer.php");?>

tsession 包含 session_start() 和会话信息..

<?php
session_start();
function tpr_logged_in()
{
return isset($_SESSION['sessionid2']);
}

function confirm_tpr_logged_in()
{ 
if(!tpr_logged_in())
{
    redirect_to("tpr_login.php");
}
}
?>

连接包含数据库初始化...问题是每当我输入正确的信息时它会显示“Out of Submit”警报,如果一个信息是错误的,那么它会进入提交并返回密码组合不正确...显然...什么是问题????

4

2 回答 2

1
<div id="main">
    <table id="structure">
        <tr>
            <td id="navigation"><a href="content.php">Return to Home</a></td>
            <td id="page">
                <h2>Login</h2>


    <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
    <form action="tpr_login.php" method="post">
    <table id="inner" cellpadding="10">
    <tr>
    <td>Select Branch</td>
    <td>

 <?php

 $con = mysql_connect("localhost","TestUserFirst","TestUserFirst");
 $db = mysql_select_db("student",$con);
 $get=mysql_query("SELECT branch_name FROM branch ORDER BY branch_ID ASC");
$option = '';
 while($row = mysql_fetch_assoc($get))
{
  $option .= '<option value =      "'.$row['branch_name'].'">'.$row['branch_name'].'</option>';
}
?>
 <select name="branch" id="branch"> 
<?php echo $option; ?>
</select>
</td>
</tr>
    <tr>
    <td>TPRId</td>
    <td><input type=text name="tprid" id="tprid" value=""></td>
    </tr><tr>
    <td>Password</td>
    <td><input type=password name="password" id="password" value=""></td>
    </tr><tr>
    <td></td>
    <td><input type="submit" name="submit" value="Login"></td>
    </tr>
    </table>
    </form>
    </td>
        </tr>
    </table>
</div>

End </form> tag after </table> instead of after </tr>.

I am not sure, but you can try this. Without checking its not possible to say the actual probelm.

于 2013-06-13T10:07:29.000 回答
0

缺少一个'";' 在下面的行中

$message = "Username/password/branch combination incorrect.<br />";
于 2013-06-13T10:20:36.040 回答