我有一个包含2个登录和注册表单的脚本。我也在同一个脚本中使用PHP代码连接到数据库并验证用户..每次运行它没有PHP代码它运行很棒。当我使用正确的语法并添加PHP代码时,它会给我空白页
由于
首先这是我放入体内的代码
if(isset($_POST['submit']))
{
include_once ('db_info.php');
//painroume ta stoixeia apo th forma me ton pinaka $_POST kai ta enapothetoume se metavlhtes
$user = $_POST['username'];
$passw = $_POST['password'];
$Crypted_passwd = password_hash($passw, PASSWORD_DEFAULT);
//vlepoume tin ip tou xrhsth kai pairnoume thn wra pou ginetai to aithma login sto server
$ip = $_SERVER['REMOTE_ADDI'];
$logtime = date("h:i:sa");
//sindesh me vash afou prwta exoume kanei include to db_info.php
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//query sth vash gia na kanoume to authedicate
$sql = "SELECT * FROM Users WHERE username='$user' AND password= '$Crypted_passwd'";
$Authedicate_user = $conn->query($sql);
if ($Authedicate_user->RecordCount()==1){
session_start();
$_SESSION['auth']=true;
$_SESSION['username']= $user;
$query2 = "UPDATE Users SET ip='$ip',time='$logtime' WHERE username='$user'" ;
$result = $conn->query($query2);
die(header("Location:app.php"));
}
else {
die(header("location:login.php?loginFailed=true&reason=password"));
}
?>
现在是html
<html>
<head>
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/animate-custom.css" />
</head>
<body>
<div class="container">
<div id="container" >
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" autocomplete="on" method='POST'>
<h1>Log in</h1>
<p>
<label for="username" class="uname" data-icon="u" > Username </label>
<input id="username" name="username" required="required" type="text" placeholder="Username"/>
</p>
<p>
<label for="password" class="youpasswd" data-icon="p"> Password </label>
<input id="password" name="password" required="required" type="password" placeholder="Password " />
</p>
<p class="login button">
<input type="submit" value="Login" id="submit" name= "submit"/>
<? $reasons = array("password" => "Wrong Username or Password", "blank" => "You have left one or more fields blank.");
if ($_GET["loginFailed"]) echo $reasons[$_GET["reason"]]; ?>
<p class="change_link">
Not a member yet ?
<a href="#toregister" class="to_register">Join us</a>
</p>
</form>
</div>
<div id="register" class="animate form">
<form action="mysuperscript.php" autocomplete="on">
<h1> Sign up </h1>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Your username</label>
<input id="usernamesignup" name="usernamesignup" required="required" type="text" placeholder="Username" />
</p>
<p>
<label for="emailsignup" class="youmail" data-icon="e" > Your email</label>
<input id="emailsignup" name="emailsignup" required="required" type="email" placeholder="email@somewhere.com"/>
</p>
<p>
<label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label>
<input id="passwordsignup" name="passwordsignup" required="required" type="password" placeholder="Password"/>
</p>
<p>
<label for="address" class="youpasswd" data-icon="p">address </label>
<input id="address" name="address" required="required" type="text" placeholder="address"/>
</p>
<p class="signin button">
<input type="submit" value="Sign up"/>
</p>
<p class="change_link">
Already a member ?
<a href="#tologin" class="to_register"> Go and log in </a>
</p>
</form>
</div>
</div>
</div>
</div>