-1

これは私の登録コードです。

フォームにフィールドを入力すると、登録は成功したと表示されますが、データベース テーブルに空白のデータが追加されます。私のmobileno列に番号0を追加します。

できるだけ早くここで私を助けてください

include ('database_connection.php');

if (isset($_POST['formsubmitted'])) {

$error = array();//Declare An Array to store any error message  

if (empty($_POST['mobileno'])) {//if no name has been supplied 
    $error[] = 'Please Enter a Mobile Number ';//add to array "error"
} else {
    $name = $_POST['mobileno'];//else assign it a variable
}
if (empty($_POST['fname'])) {//if no name has been supplied 
    $error[] = 'Please Enter a First name ';//add to array "error"
} else {
    $name = $_POST['fname'];//else assign it a variable
}
if (empty($_POST['lname'])) {//if no name has been supplied 
    $error[] = 'Please Enter a Last name ';//add to array "error"
} else {
    $name = $_POST['lname'];//else assign it a variable
}
if (empty($_POST['email'])) {
    $error[] = 'Please Enter your Email ';
} else {


    if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-    Z0-9\._-]+)+$/", $_POST['email'])) {
       //regular expression for email validation
        $Email = $_POST['email'];
    } else {
         $error[] = 'Your EMail Address is invalid  ';
    }


}


if (empty($_POST['passwd1'])) {
    $error[] = 'Please Enter Your Password ';
} else {
    $Password = $_POST['passwd1'];
}
if (empty($_POST['passwd2'])) {
    $error[] = 'Please Verify Your Password ';
} else {
    $Password = $_POST['passwd2'];
}

if (empty($error)) //send to Database if there's no error '

{ //If everything's OK...

    // Make sure the mobile no is available:
    $query_verify_mobileno = "SELECT * FROM userdtls WHERE mobileno = '$mobileno'";
    $result_verify_mobileno = mysqli_query($dbc, $query_verify_mobileno);
    if (!$result_verify_mobileno) 
    {//if the Query Failed ,similar to if($result_verify_mobileno==false)
        echo ' Database Error Occured ';
    }

    if (mysqli_num_rows($result_verify_mobileno) == 0) { // IF no previous user is using this number .


        // Create a unique  activation code:
       $activation = md5(uniqid(rand(), true));


        $query_insert_user = "INSERT INTO userdtls (`mobileno`, `pass`, `fname`, `lname`, `email`, `activation`) VALUES ( '$mobileno', '$passwd1', '$fname', '$lname', '$email', '$activation')";


        $result_insert_user = mysqli_query($dbc, $query_insert_user);
        if (!$result_insert_user) {
            echo 'Query Failed ';
        }

        if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull.


            // Send the email:
          $message = " To activate your account, please click on this link:\n\n";
            $message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&key=$activation";
            mail($Email, 'Registration Confirmation', $message, 'From: rahul19dj@gmail.com'); 

            // Flush the buffered output.


            // Finish the page:
            echo '<div class="success">Thank you for registering! A confirmation email has been sent to '.$email.' Please click on the Activation Link to Activate your account </div>';


        } else { // If it did not run OK.
            echo '<div class="errormsgbox">You could not be registered due to a system error. We apologize for any inconvenience.</div>';
        }

    } else { // The mobile number is not available.
        echo '<div class="errormsgbox" >That mobile number has already been registered.</div>';
    }

} else {//If the "error" array contains error msg , display them



 echo '<div class="errormsgbox"> <ol>';
    foreach ($error as $key => $values) {

        echo '  <li>'.$values.'</li>';



    }
    echo '</ol></div>';

}

mysqli_close($dbc);//Close the DB Connection

} // End of the main Submit conditional.
4

1 に答える 1

1

各変数を連続して上書きすることを除いて、すべての変数を割り当てています$email$nameこれは間違いなく、データベース内の各列のデータ型に依存する奇妙な結果を引き起こします。mobilenoに設定されている場合、文字列または空の値intのデフォルト値があり0、データベースに 0 が表示されます。

于 2012-08-01T03:36:53.537 に答える