我正在培训和安置网站工作,我遇到了一个小问题,但我被困住了......希望我会得到帮助.. 登录页面的代码如下: 这是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”警告,如果一个信息错误则进入提交并返回密码组合不正确......显然..什么问题????
答案 0 :(得分: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>
在</form>
之后而不是在</table>
之后结束</tr>
代码。
我不确定,但你可以尝试一下。没有检查它不可能说实际的问题。
答案 1 :(得分:0)
缺少'\ n';'在下面一行
$message = "Username/password/branch combination incorrect.<br />";