CSS弹出登录表单和PHP登录脚本

时间:2013-03-18 12:52:21

标签: php html css

我有一个CSS弹出窗口,它会显示一个登录表单。当我尝试登录时,只需重新加载页面,然后再次出现弹出窗口。

这是打开弹出窗口的链接

<a href="#login_form" class="btn signInBtn">Sign In</a>

以下是我的弹出式登录表单的HTML。

<a href="#x" class="overlay" id="login_form"></a>    
    <div class="popup">
        <h2 class="modal-header">Sign In</h2>
        <div class="modal-body">
            <form class="signIn-form">
                <div class="errorMessage alert alert-error" id="errorMsg">
                    <h4>Whoops</h4>
                    <p>
                        <?php echo $errorMsg; ?>
                    </p>
                </div>
                <fieldset class="l-formMain">
                    <ul>
                        <li>
                            <label class="applyForm-label" for="email">Email</label>
                            <input class="applyForm-input required" type="email" id="login_email" placeholder="name@example.com" tabindex="1" />
                        </li>
                        <li>
                            <label class="applyForm-label" for="password">Password</label>
                            <input class="applyForm-input required" type="password" id="login_password" tabindex="2" />
                            <span class="forgotPassLi">
                                <a href="#forgotpass" class="v-secondary" style="position:relative; left:-150px;">Forgot your Password?</a>
                            </span>
                        </li>
                    </ul>
                </fieldset>
                <div class="modal-buttonHolder">
                    <input type="submit" class="btn btn-large" id="login" value="Sign In" tabindex="3" />
                </div>                    
            </form>
        </div> 
        <a href="#close" class="modal-closeBtn">×</a>       
    </div> 

这是我的PHP:

if(isset($_POST['login'])){
    $login_email = $_POST['login_email'];
    $login_password = $_POST['login_password'];

    // error handling conditional checks go here
    if ((!$login_email) || (!$login_password)) { 
    $errorMsg = 'Please fill in both fields';
    } else { // Error handling is complete so process the info if no errors
    include 'scripts/connect_to_mysql.php'; // Connect to the database
    $email = mysql_real_escape_string($login_email); // After we connect, we secure the string before adding to query       
    $pass = md5($login_password); // Add MD5 Hash to the password variable they supplied after filtering it     
    // Make the SQL query
    $sql = "SELECT * FROM members WHERE email='$email' AND password='$password' AND email_activated='1'";
           $result = mysql_query($sql); 
    if($result){
        $login_check = mysql_num_rows($result);
    }   
    // If login check number is greater than 0 (meaning they do exist and are activated)
    if($login_check > 0){ 
            while($row = mysql_fetch_array($result)){

                $id = $row["ID"];
                $_SESSION['ID'] = $id;
                // Create the idx session var
                $_SESSION['idx'] = base64_encode("xxxxxxxxxxxxxxxxxxx$id");
                // Create session var for their username
                $email = $row["email"];
                $_SESSION['email'] = $email;
                $_SESSION['userId'] = $row["ID"];

                mysql_query("UPDATE members SET last_log_date=now() WHERE ID='$id' LIMIT 1");

            } // close while
            // All good they are logged in, send them to homepage then exit script
            if (isset($_SESSION["email"]) || count($_SESSION["email"]) > 0) {  
                header("Location: http://localhost/dashboard.php");
            }               
    } else { // Run this code if login_check is equal to 0 meaning they do not exist
        $errorMsg = "Either the email or password (or both) are incorrect. Make sure that you've typed them correctly and try again";
    }
    }// Close else after error checks
    }
?>

1 个答案:

答案 0 :(得分:0)

您的表单未发布到任何地方。所以默认情况下它会转到当前页面。

尝试向表单添加操作和方法属性:

<form method="post" action="http://url.of.PHP.page/containing/login/code">
相关问题