0

I am new to php and I am making a simple registration form and storing the values in database, this include texts as well as image.
But during submit button I am getting an error Fill all the details which I am not expecting.
Here is the registration form

<form action="php scripts\register.php" method="post" enctype="multipart/form-data">
 <fieldset>
  <legend>Event Registeration</legend>
  <div class="left">Full Name</div> <div class="right"><input type="text" required = "required" placeholder="e.g. : Sachin Sharma" name = "full_name"></div><br><br>
  <div class="left">Mobile</div><div class="right"><input type="text" required = "required" placeholder="+91" name= "mobile_number"></div><br><br>
  <div class="left">Email</div> <div class="right"><input type="text" required = "required" name = "email" placeholder="email"></div><br><br>
  <div class="left">ID</div><div class="right"><input type="file" required="required" name="ID" id="id_card"></div><br><br>
  <div class="left">Registeration type</div><div class="right"> <select name="registrationType">
  <option value="student">student</option>
  <option value="teacher">teacher</option>
  <option value="principle">principle</option>
  <option value="other">Others</option>
</select></div><br><br>
  <div class="left">Number</div><div class="right"><input type="number" value="1" name = "number" required="required"></div><br><br>
  <button class="preview">Preview</button><button class = "submit">Submit</button>
 </fieldset>
</form>

This is the register.php file

<?php
require_once 'DB_Functions.php';
$db = new DB_Functions();
if(var_dump(isset($_POST['full_name'],$_POST['mobile_number'],$_POST['email'],$FILES['IDCard'],$_POST['registrationType'],$_POST['number']))){
    $full_name = $_POST['full_name'];
    $mobile_number = $_POST['mobile_number'];
    $email = $_POST['email'];
    $idCard = $FILES['ID'];
    $registrationType = $_POST['registrationType'];
    $number = $_POST['number'];
    //Check if the user exist
    if($db->isUserExisted($mobile_number)){
        die ("You have already registered");
    }
    else{
        $user = $db->storeUser($full_name,$mobile_number,$email,$idCard,$registrationType,$number);
        if($user){
            echo "You have successfully registered";
        }
        else{
            die ("Unknown error occured during registeration");
        }
    }
}
else{
    echo "Fill all the details";
}
?>

And this is the DB_Functions.php file

public function saveUser($fullName,$mobileNumber,$email,$IDCard,$registerationType,$numberofTickets){
        $uuid = uniqid('',true);
        $target_dir = "latitude_fintech/userPictures/";
        $target_file = $target_dir . basename($_FILES["IDCard"]["name"]);
        $uploadOk = 1;
        $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
        $check = getimagesize($_FILES["IDCard"]["tmp_name"]);
        if($check !== false) {
            echo "File is an image - " . $check["mime"] . ".";
            $uploadOk = 1;
        } else {
            die("File is not an image.");
            $uploadOk = 0;
        }
        // Check if file already exists
        if (file_exists($target_file)) {
            die("Sorry, file already exists.");
            $uploadOk = 0;
        }
        // Check file size
        if ($_FILES["IDCard"]["size"] > 500000) {
            die("Sorry, your file is too large.");
            $uploadOk = 0;
        }
        // Allow certain file formats
        if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" ) {
            die("Sorry, only JPG, JPEG & PNG files are allowed.");
            $uploadOk = 0;
        }
        if ($uploadOk == 0) {
            die("Image should be png or jpg type only.");
        }
        else{
            if (move_uploaded_file($_FILES["IDCard"]["tmp_name"], $target_file)){

        //Store information
        $stmt = $this->conn->prepare("INSERT INTO registeration_table(uniqueId, fullName, mobileNumber, email,idCard,registerationType,Tickets,
        registerationDate) VALUES(?,?,?,?,$target_dir,?,?,NOW())");
        $stmt->bind_param("sssssss",$uuid, $fullName,$mobileNumber,$email, $idCard, $registerationType,$numberofTickets);
        $result = $stmt->execute();
        $stmt->close();
        //Check for store
        if ($result) {
            $stmt = $this->conn->prepare("SELECT * FROM registeration_table WHERE mobileNumber = ?");
            $stmt->bind_param("s", $mobileNumber);
            $stmt->execute();
            $user = $stmt->get_result()->fetch_assoc();
            $stmt->close();
            return $user;
        } else {
            return false;
        }
        }
        else {
                die("Sorry, there was an error uploading your file.");
        }
        }
    }

Any help would be highly appreciated
Thanks you.

  • `isset($_POST['ID'])` most likely fails, your form does not have a field named `ID` (it's called `IDCard`). – ccKep Jan 22 '17 at 05:36
  • @ccKep I correct that one still fails –  Jan 22 '17 at 05:42
  • On a side-note: `isset` accepts multiple parameters and returns true if **all** are set, so you can just do `if (isset($_POST['full_name'], $_POST['mobile_number'], ...))`. – ccKep Jan 22 '17 at 05:45
  • `var_dump` your individual `isset` results (eg. `var_dump(isset($_POST['full_name']));`) and post which one fails. – ccKep Jan 22 '17 at 05:46
  • @ccKep Yea thank you I changes that but still the same error –  Jan 22 '17 at 05:48
  • `print_r($_POST)` what is/isnt set, you need to identify the cause of the `else` firing. – chris85 Jan 22 '17 at 05:48
  • @ccKep this time it says bool(false) Fill all the details –  Jan 22 '17 at 05:49
  • Yes, thats why you enter the `else`. Look at the `POST` and see what index is not there. – chris85 Jan 22 '17 at 05:50
  • @luke for which field? Also: You're still checking `$_POST["ID"]` instead of `$_FILES["ID"]`. – ccKep Jan 22 '17 at 05:50
  • no no I changed that to $_FILES["ID"] into my code –  Jan 22 '17 at 05:51
  • The field is not mentioned there –  Jan 22 '17 at 05:53
  • You should know which field you're checking since you wrote it in your code (eg. full_name in my example up there). You can just `var_dump($_POST)` aswell and just edit the result in your question. – ccKep Jan 22 '17 at 05:53
  • I did not mean you should `if (var_dump(isset(...)))`, I meant for you to put that **before** the if, in addition to your current code. – ccKep Jan 22 '17 at 05:56

1 Answers1

0

why you are checking isset($_POST['ID'])

there is no field name as 'ID' in your form. Yes you have 'IDCard' as field name.

But it is file type so you can get its data using "$_FILES" not "$_POST"

B. Desai
  • 16,264
  • 5
  • 24
  • 44
  • post your edited answer. Dont check value of ID using $_POST['ID']. As it is file input you have to check using $_FILES['ID'] – B. Desai Jan 22 '17 at 05:43
  • It says the same thing fill all the details –  Jan 22 '17 at 05:44
  • Dont check value of ID using $_POST['ID']. As it is file input you have to check using $_FILES['ID']. I already mention it in my answer – B. Desai Jan 22 '17 at 05:47
  • yea i changed that too –  Jan 22 '17 at 05:49
  • its not $FILES it is $_FILES – B. Desai Jan 22 '17 at 05:53
  • its not $FILES it is $_FILES – B. Desai Jan 22 '17 at 06:02
  • thank you I corrected that one but there is another issue with image file and the error is Warning: getimagesize(): Filename cannot be empty in C:\xampp\htdocs\latitude_fintech\php scripts\DB_Functions.php on line 17 File is not an image. –  Jan 22 '17 at 06:07
  • are you uploading image file? This error warning may be because of you are uploading non image file(like txt/pdf/dec etc). Also if you resolve your main problem then accept my answer. – B. Desai Jan 22 '17 at 06:23
  • I corrected that one this time its givng me this error Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\latitude_fintech\php scripts\DB_Functions.php on line 48 –  Jan 22 '17 at 06:28
  • refer this : http://stackoverflow.com/questions/27394710/fatal-error-call-to-a-member-function-bind-param-on-boolean – B. Desai Jan 22 '17 at 06:32