我做了一个登录表单,我遇到了很多其他问题,现在我发现 PHP 代码是在提交之前执行的。如何解决问题?由于 PHP 不支持 onclick 事件(这很糟糕!),我没有看到任何我知道的解决方案!
代码:
//Get the form with POST
$user = mysql_real_escape_string($_POST['user']);
$password = mysql_real_escape_string($_POST['pass']);
$usernames=mysql_query("SELECT * FROM user_info WHERE Username='" . $_POST['user'] . "' AND Password='" . $_POST['pass'] . "'");
if(!$usernames){echo mysql_error();}
$count=mysql_num_rows($usernames);
if(!$count){echo mysql_error();}
//If $count is equal to one, register the user and redirect him to his page, or else echo him that his info is wrong
if($count === 1) {
$_SESSION['code'] = "titan";
$_SESSION['ande'] = $user;
$_SESSION['password'] = $password;
header("location: home.php");}
else {
echo "<p style='color:red;text-align:center;'>Wrong username or password!</p>";}