用php中的数据库中的数据制作一个特定的季节

时间:2014-01-23 14:12:37

标签: php html

我有一个代码,当用户登录他/她的重新编码时,也会转移到下一页...但是用户只会在登录页面输入用户名和密码,但在下一页中他/她repcode被传递到ned页面....任何人都可以帮助我...我试图弄清楚它已经2个小时了...我的头疼...帮助我们。

ex tb_name ='id','name','username','password','repcode'

第1页:

<!DOCTYPE html>
<?php 
ob_start();
session_start();

include('include/connect.php');

?>

<html>
<head>
<title>test</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="username">
<input type="text" name="password">
<input type="hidden" name="repcode" value="<?php $repcode ?>">
<input type="submit" name="login" id="send" />
</form> 
</body>
</html>

<?php
// Inialize session
if(isset($_POST['login'])){
$username=$_POST['username'];
$password=$_POST['password'];
// Include database connection settings
include('connection.php');
// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM users WHERE username = '$username' and password = '$password'");

// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
$repcode1 = mysql_query("SELECT repcode FROM users WHERE username = '$username");
while($row = mysql_fetch_array($repcode1))
    {
        $repcode = $row['repcode'];                        
    } 
$_SESSION['repcode'] = $repcode;
// Jump to secured page
$stat="UPDATE users SET status='login'";
mysql_query($stat); 
header('Location: home2.php');
}
else {
}
}
?>

第2页:

<!DOCTYPE html>
<?php 
ob_start();
session_start();
include('include/connect.php');
?>
<html>
<head>
<title>test</title>
</head>
<body>
<form method="get" >
  <input type="text" name="username" value="<?php echo $_SESSION['username']; ?> "/>
  <input type="text" name="repcode" value="<?php echo $_SESSION['repcode']; ?> "/>
</form></body>
</html>

我想在第二页显示用户的重新编码,但我现在的代码不需要帮助。

1 个答案:

答案 0 :(得分:0)

您错过了获取重新编码的mysql查询中的单引号,因此请更改:

$repcode1 = mysql_query("SELECT repcode FROM users WHERE username = '$username");

到此:

$repcode1 = mysql_query("SELECT repcode FROM users WHERE username = '$username'");

此外,不推荐使用mysql_ *函数。你应该使用mysqli_ *函数。