简体   繁体   English

注册验证

[英]Signup Verification

Every time I leave any textbox unfilled for the 1st time, it would be registered to the db same as if I leave all the textboxes empty but when you do it for the 2nd time (any of the two), that would be the time the alert box would pop-up... I don't what to do. 每次我第一次不填写任何文本框时,都会将其注册到数据库,就像我将所有文本框都保留为空白一样,但是当您第二次这样做时(两个中的任何一个),那将是警报框会弹出...我不知道该怎么办。 Help me please. 请帮帮我。 Here's my code: 这是我的代码:

<?php

ini_set('display_errors', 0);
$email= $_POST['email'];
$user= $_POST['user'];
$password= $_POST['password'];
$image =($_FILES['image']['name']);
$submit= $_POST['submit'];

if (empty($email) || empty($password) || empty($user) ) 
{
    echo "<script type='text/javascript'>
    alert('You did not complete all of the required fields');
    window.location='blah2.php';
    </script>";  
}


if(isset($submit))
{   
    $con = mysqli_connect("localhost", "root", "", "top")
        or die('error in connection'.mysqli_connect_error());

        $q = "SELECT username , email FROM registries WHERE username = ? OR email = ?";     
        $stmt = mysqli_prepare ($con, $q);
            mysqli_stmt_bind_param($stmt, 'ss', $user, $email);
            mysqli_stmt_execute($stmt);
            mysqli_stmt_bind_result($stmt, $user , $email);
            mysqli_stmt_store_result($stmt);
            $result = mysqli_stmt_num_rows($stmt);

    if($result > 0) 
    { 
        echo "<script type='text/javascript'>
              alert('Email address or Username is already taken. Please pick another one.');
              window.location='blah2.php';
              </script>";       
    }   
    else
    {

        $q="INSERT INTO registries VALUES (?,?,?,?)";
        $stmt = mysqli_prepare($con, $q);
                move_uploaded_file($_FILES["image"]["tmp_name"],"uploads/" . $_FILES["image"]["name"]);
                mysqli_stmt_bind_param($stmt, 'ssss', $email, $user, $password, $image);
                mysqli_stmt_execute($stmt);
                mysqli_stmt_store_result($stmt);

                mysqli_stmt_close($stmt);

                header('Location: blah.php');


    }   

}

If I understand you right then just move 如果我理解你没错,那就动一下

if(isset($submit)){

on top of your code right after 在代码之后

ini_set('display_errors', 0);

with this 有了这个

$submit= $_POST['submit']; 

$submit is always set 始终设置$submit

maybe you could try 也许你可以尝试

if (isset($_POST['Submit']))

and for debugging purpose you could try to var_dump $email , $password and $user and check if maybe they are really empty when you post your form once or twice 出于调试目的,您可以尝试var_dump $email$password$user并检查一次或两次发布表单时它们是否真的为空

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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