注册验证

时间:2013-10-09 15:48:48

标签: javascript php mysqli verification

每当我第一次留下任何未填充的文本框时,它都会被注册到数据库,就像我将所有文本框都留空但当你第二次执行它时(两者中的任何一个),那将是警报框弹出的时间......我不知道该怎么做。 请帮帮我。 这是我的代码:

<?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');


    }   

}

2 个答案:

答案 0 :(得分:0)

如果我理解你,那就移动

if(isset($submit)){

之后

代码顶部

ini_set('display_errors', 0);

答案 1 :(得分:0)

用这个

$submit= $_POST['submit']; 
始终设置

$submit

也许你可以试试

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

出于调试目的,您可以尝试var_dump $email$password$user并检查在您发布一次或两次表单时它们是否真的是空的