我目前正在构建一个非常非常基本的登录脚本,它基本上连接到数据库,并检查用户在表单中输入的值是否匹配。但是,由于某种原因,当单击提交按钮时,我的代码拒绝执行任何操作!??这是代码...
<?php
mysql_connect("localhost", "username", "password");
mysql_select_db("dbname");
?>
<body>
<?php
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
$num = mysql_num_rows($result);
if($num == 0){
echo "Bad login, go <a href='login.php'>back</a>.";
}else{
session_start();
$_SESSION['username'] = $username;
header("Location: admin.php");
}
}else{
?>
<form action='login.php' method='post'>
Username: <input type='text' name='username' /><br />
Password: <input type='password' name='password' /><br /><br />
<input type='submit' value='Login' />
</form>
<?php
}
?>
</body>
有任何想法吗?