PHP/MySQL 会员系统总是给我已经注册了电子邮件

标签: MySQL PHP
发布时间: 2016/10/15 19:47:48
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

会员系统代码总是把我重定向到"电子邮件已经注册页面"
这就是使用在处理检查代码是否电子邮件,那将是用户名,
是已经采取或不
请帮助!!!

<?php
    $db_host = "localhost";
    $db_user = "ms_admin";
    $db_pass = "secretpassword";
    $db_name = "member_system";

     $connection = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

    if(mysqli_connect_errno())
        die("Databse connection failed." . mysqli_connect_error()
            . " (" . mysqli_connect_errno() . ")" );
?>

<?php

    function check_email($e_mail)
    {
        $query  = "SELECT email FROM members ";
        $query .= "WHERE email='$e_mail'";

        $result = mysqli_query($connection, $query);
        $num_rows = mysqli_num_rows($result);

        if($num_rows>0) header("Location: registration_successful.php");
         else header("Location: registration_unsuccessful.php");
    }
?>

<?php
    $full_name = ucwords($_POST["full_name"]);
    $email = strtolower($_POST["email"]);
    $password = md5($_POST["password"]);

    check_email($email);
?>

我改变了那些︰

 if($num_rows>0) header("Location: registration_successful.php");
  else header("Location: registration_unsuccessful.php");

自:

 if($num_rows>0) header("Location: registration_unsuccessful.php");
  else header("Location: registration_successful.php");


看来,($num_rows > 0) 总是返回 FALSE:(

请帮忙,谢谢...

解决方法 1:

$connection 变量请失踪在 check_email() 套 global $connection; 像 db 连接

function check_email($e_mail){
        global $connection;
        $query  = "SELECT email FROM members ";
        $query .= "WHERE email='$e_mail'";

        $result = mysqli_query($connection, $query);
        $num_rows = mysqli_num_rows($result);

        if($num_rows>0) header("Location: registration_successful.php");
         else header("Location: registration_unsuccessful.php");
     }


     check_email($email);

 function check_email($e_mail, $connection){
    $query  = "SELECT email FROM members ";
    $query .= "WHERE email='$e_mail'";

    $result = mysqli_query($connection, $query);
    $num_rows = mysqli_num_rows($result);

    if($num_rows>0) header("Location: registration_successful.php");
     else header("Location: registration_unsuccessful.php");
 }


 check_email($email, $connection);

虽然我喜欢第一个:)

官方微信
官方QQ群
31647020