dimanche 2 avril 2017

It does not insert image into database?

this the php code for inserting image.. I am doing it with postman.. also there is a foreign key... when i did it without forwign key .. it inserted the image.. but after adding foeign key it is not working.. P.S i am inserting the foriegn key by myselft since its postman.. i take the id of the other table and insert it in this table.. please help thanks

<?php
    include 'connection.php';
    $target_dir = "Upload/";
    $target_file_name = $target_dir .basename($_FILES["file"]["name"]);
    $branchid = $_POST["branchid"];
    //$Post_title=$_POST["Post_title"];
      // $Post_Area=$_POST["Post_Area"];


    $response = array();

    // Check if image file is a actual image or fake image
    if (isset($_FILES["file"])) 
    {
     if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file_name)) 
     {
       $query=mysqli_query($conn,"INSERT INTO images(br_id, name) VALUES ('$branchid','$target_file_name')");
       if($query){
      $success = true;
      $message = "Successfully Data Uploaded";
       }
       else
       {
        $success = true;
      $message = "Successfully Uploaded";

       }
     }
     else 
     {
      $success = false;
      $message = "Error while uploading";
     }
    }
    else 
    {
     $success = false;
     $message = "Required Field Missing";
    }

    $response["success"] = $success;
    $response["message"] = $message;
    echo json_encode($response);

    ?>

this is the error it gives..

Notice: Undefined index: file in C:\xampp\htdocs\school\uploadimage.php on line 4

Notice: Undefined index: branchid in C:\xampp\htdocs\school\uploadimage.php on line 5
{"success":false,"message":"Required Field Missing"}




Aucun commentaire:

Enregistrer un commentaire