【发布时间】:2014-01-23 11:13:38
【问题描述】:
我有以下代码:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<form name="form1" method="POST">
<table>
<tr>
<td>Username</td>
<td> <input type="text" name="text1"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pwd"></td>
</tr>
<tr>
<td><input type="submit" name="submit1"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
include 'config.php';
mysql_select_db("sess_db",$con);
?>
<?php
if(isset($_POST['submit1'])) {
$result=mysql_query("SELECT username,password FROM siteinfo ");
$result2=mysql_fetch_row($result);
$count=mysql_num_rows($result);
$nm = $_POST['text1'];
$pwd = $_POST['pwd'];
if ($result == $nm && $result == $pwd) {
$_SESSION['luser'] = $name;
$_SESSION['start'] = time();
//the expire u put it
$_SESSION['expire'] = $_SESSION['start'] + (30 * 60);
header('Location: homepage.php');
}
else {
echo "Please Enter a Correct Username & Password ! ";
}
}
?>
在登录页面我必须输入用户名:joseph 和密码:moon
但我想删除这两个变量 $name 和 $password 并将其链接到包含用户名和密码的数据库,如果我输入其中一个变量会将我重定向到
主页.php
【问题讨论】:
-
首先在你的
<?php之后添加session_start(); -
您的问题表明您不知道如何在 PHP 中与数据库进行交互。你应该先阅读一些文档或教程
-
我添加了它@ShankarDamodaran
-
我知道如何连接它,但问题我不知道我必须把它放在哪里@Tounu
-
使用输出之前
标签: php mysql database session