gpt4 book ai didi

php - php 中的 sql 运行时不返回任何内容

转载 作者:行者123 更新时间:2023-11-29 21:55:06 24 4
gpt4 key购买 nike

每次我尝试登录时,页面都会刷新,但没有任何反应。我可以破坏 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>

最佳答案

try catch mysql 中的错误。使用mysqli_error()

$query="SELECT * FROM `login` WHERE email='".mysqli_real_escape_string($link, $_POST['email'])."'";
$result=mysqli_query($link, $query);
if($result == false) {
echo mysqli_ee($link)." ".mysqli_error($link);
}

关于php - php 中的 sql 运行时不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33226438/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com