0
每次嘗試登錄時,頁面都會刷新並且什麼都不會發生。我可以打破這個PHP並讓它返回一個錯誤,但是現在寫出來,沒有錯誤發生。這是我第一次使用SQL,我渴望學習,所以任何和所有的幫助是巨大的讚賞。php中的sql在運行時不會返回任何東西
<?php
session_start();
$link=mysqli_connect("localhost", "cl44-thediary", "password", "cl44-thediary");
if ($_POST["submit"]=="Sign Up") {
if (!$_POST["email"]) $error.="<br />Please enter your email.";
else if (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) $error.="<br/>Please enter a valid email address.";
if (!$_POST["password"]) $error.="<br />Please enter your password.";
else {
if (strlen($_POST["password"])<8) $error.="<br />Please enter a password with at least 8 characters.";
if (strlen($_POST["password"])>55) $error.="<br />Please enter a password with less than 55 characters.";
if (!preg_match('`[A-Z]`', $_POST["password"])) $error.="<br />Please include at least one capital letter in your password.";
if (!preg_match('`[0-9]`', $_POST["password"])) $error.="<br />Please include at least one number in your password.";
if (!preg_match('`[a-z]`', $_POST["password"])) $error.="<br />Please include at least one lower-case letter in your password.";
};
if ($error) echo "There were error(s) in your signup details".$error;
else {
$query="SELECT * FROM `login` WHERE email='".mysqli_real_escape_string($link, $_POST['email'])."'";
$result=mysqli_query($link, $query);
$results=mysqli_num_rows($result);
if ($results) echo "That email address is already registered. Do you want to login?";
else {
$query="INSERT INTO `login` (`email`, `password`) VALUES('".mysqli_real_escape_string($link, $_POST['email'])."','".md5(md5($_POST['email']).$_POST['password'])."')";
mysqli_query($link, $query);
echo "You've signed up!";
$_SESSION["id"]=mysqli_insert_id($link);
print_r($_SESSION);
//Redirect to logged in page
}
}
}
if ($_POST["submit"]=="Login") {
$query="SELECT * FROM `login` WHERE email='".mysqli_real_escape_string($link, $_POST['LoginEmail'])."' AND password='".md5(md5($_POST['LoginEmail']).$_POST['loginPassword'])."' LIMIT 1";
$result=mysqli_query($link, $query);
$row=mysqli_fetch_array($result);
print_r($row);
};
?>
<form method="post">
<input type="email" name="email" id="email" value="<?php echo addslashes($_POST['email']);?>"/>
<input type="password" name="password" id="password" value="<?php echo addslashes($_POST['password']);?>"/>
<input type="submit" name="submit" value="Sign Up"/>
</form>
<form method="post">
<input type="email" name="loginEmail" id="loginEmail" value="<?php echo addslashes($_POST['loginEmail']);?>"/>
<input type="password" name="loginPassword" id="loginPassword" value="<?php echo addslashes($_POST['loginPassword']);?>"/>
<input type="submit" name="submit" value="Login"/>
</form>
你真的應該把它切成[mcve]。 – Teepeemm