简体   繁体   中英

sql in php doesn't return anything when run

Every time I try and login, the page refreshes and nothing happens. I can break the php and get it to return an error, but as it is written now, no error occurs. This is my first time using SQL and I'm eager to learn so any and all help is mega-appreciated.

<?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 catching the error in mysql. using 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM