1

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

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


    }   

}
4

2 回答 2

0

with this

$submit= $_POST['submit']; 

$submit is always set

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

于 2013-10-09T16:04:35.803 回答
0

如果我理解你的话,那就搬家吧

if(isset($submit)){

在你的代码之上

ini_set('display_errors', 0);
于 2013-10-09T15:55:01.300 回答