初学者在这里使用PHP。有一个简单的HTML表单,调用此login.php:
<?php
require ('sql_connect.php');
if (isset($_POST['submit'])){
$username=mysql_escape_string($_POST['uname']);
$password=mysql_escape_string($_POST['pass']);
if (!$_POST['uname'] | !$_POST['pass'])
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('You did not complete all of the required fields')
window.location.href='htmlogin.html'
</SCRIPT>");
exit();
}
$sql= mysql_query("SELECT * FROM `members` WHERE `username` = '$username' AND `password` = '$password'");
$row= mysql_fetch_assoc($sql);
$url=$row['defaultpage'];
header($url);
if($username !== null)
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Login Succesfully! I will now direct you to $url')
window.location.href='htmllogin.html'
</SCRIPT>");
exit();
}
else{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Wrong username password combination.Please re-enter.')
window.location.href='htmllogin.html'
</SCRIPT>");
exit();
}
}
else{
}
?>
我已成功绑定到数据库(mySQL),并添加了一个名为“defaultpage”的列,其中包含完整的URL。我的目标是,一旦用户登录,它将重定向到我在数据库中指定的页面(通过'defaultpage')
任何帮助都会很棒。
非常感谢你们。