数据从数据库中检索但不会插入?

时间:2016-09-29 19:36:50

标签: php mysql mysqli

因此,当我想检索数据并检查它时,即电子邮件是否已经存在已经注册的回声。该部分工作正常,但插入相同的数据不起作用。我的条件是否订购不当? (故意省略dbhostname id pw变量的值)

$dbname = "hw2";

$link = mysqli_connect($dbhostname, $dbuserid, $dbpassword, $dbname);

$firstname = $_POST["signup-firstname"];
$lastname = $_POST["signup-lastname"];
$email = $_POST["signup-email"];
$password = $_POST["signup-password"];
$repassword = $_POST["signup-repassword"];

if ($password != $repassword){
    echo "<br><h3>Passwords did not match. <br>Please try again.</h3>";
}

else {

$ret_email = "SELECT * FROM hw2 WHERE email = '$email'";
$result = mysqli_query($link, $ret_email);
$num_rows = mysqli_num_rows($result);

    if ($num_rows > 0){
    echo "This email is already registered.";
    }   

    else{
    $insert_query = "INSERT INTO hw2 (firstname, lastname, email, password, repassword) VALUES ('$firstname', '$lastname', '$email', '$password', '$repassword')";
    echo "$insert_query";
    }       
}
?>

1 个答案:

答案 0 :(得分:1)

您应该执行查询,而不仅仅是回显它

public DateTime GetNextTestDate(DateTime testDate, bool passed)
{
    if (passed)
    {
        if (testDate.Month >= 3 && testDate.Month < 9)
            return new DateTime(testDate.Year, 9, 30);
        else
            return new DateTime(testDate.Year + (testDate.Month >= 9 && testDate.Month <= 12 ? 1 : 0), 3, 31);  // (add a year if we're 9-12)
    }
    else
        return testDate.AddDays(90);
}