failed upload image to database

sun station

So i wrote this script and i kept getting failed to upload message, please point out where i did wrong and please give a good example for the script. The image wasn't uploaded to database, but it was moved to the directory 'upload/'. And the $start & $stop variable was in date. I'd stuck in this one for several days. Here's the code.

include "../config/database.php";

$title = $_POST['title'];
$id = $_POST['id'];
$genre = $_POST['genre'];
$start = $_POST['start'];
$stop = $_POST['stop'];
$description = $_POST['description'];

$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);

$uploadOK = 1;

$imagetype = pathinfo($target_file, PATHINFO_EXTENSION);

if (isset($_POST["submit"])) {
    $check = getimagesize($_FILES["image"]["tmp_name"]);
    if ($check !== false) {
        echo "File is an image -" . $check["mime"] . ".";
        $uploadOK = 1;
    } else{
        echo "File isn't an image.";
        $uploadOK = 0;
    }
}

if (file_exists($target_file)) {
    echo "Sorry, file is already exist.";
    $uploadOK = 0;
}
if ($_FILES["image"]["size"] > 5000000) {
    echo "Sorry, file is too large.";
    $uploadOK = 0;
}

if ($imagetype != "jpg" && $imagetype != "jpeg" && $imagetype != "png" && $imagetype != "gif") {
    echo "Sorry, only JPEG, JPG, PNG and GIF are allowed.";
    $uploadOK = 0;
}

if ($uploadOK == 0) {
    echo "Failed to upload.";
} else {
    if(move_uploaded_file($_FILES["image"]["tmp_name"] , $target_file)){

        $query = mysql_query("INSERT INTO anidata (id, title, image, genre, start, stop, description) VALUES ('$title', '$id', '$target_file', '$genre', '$start', '$stop', '$description') ");
        $uploadOK = 1;

        if ($query) {
            header("Location: view.php");
        }else{
            echo "<p>Failed to upload</p>";
        }
    }
}

I really appreciate any help, thank you :)

tkounenis

Your query's values look like they are not in the correct order ($id and $title should be the other way round). Change this;

$query = mysql_query("INSERT INTO anidata (id, title, image, genre, start, stop, description) VALUES ('$title', '$id', '$target_file', '$genre', '$start', '$stop', '$description') ");

to this;

$query = mysql_query("INSERT INTO anidata (id, title, image, genre, start, stop, description) VALUES ('$id', '$title', '$target_file', '$genre', '$start', '$stop', '$description') ");

Also make sure that your variables types are in accordance with your table's fields (e.g. you don't try to save a string where an integer should be).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Failed to upload an image

From Dev

PHP Upload image into database

From Dev

Upload image to SQL Database

From Dev

Image Upload into Database

From Dev

Upload Image with FileUpload and Stock in database

From Dev

Upload Name changing image to the database

From Dev

Image Upload to mysql database not working

From Dev

Image Upload In SQLite Database Android

From Dev

Vaadin upload image and store it to database

From Dev

Codeigniter image upload and path to database

From Dev

CodeIgniter: Upload Image to path and database

From Dev

Flutter Dio: Failed Upload Image to Server

From Dev

Failed to open stream? Image upload but are not echoing

From Dev

Remove image from content after failed upload

From Dev

Best implementation of: upload image file into database and read image from database

From Dev

Cant upload and store the image to the database by using php

From Dev

What is proper way to upload a image to a MySQL database?

From Dev

slim php framework image upload put database

From Dev

Upload image to file and information to mysql database

From Dev

Image upload in a clustered tomcat, database or file system

From Dev

Upload Image to Server and Store in MySQL Database

From Dev

How to upload an image and save it to database in Codeigniter?

From Dev

PHP Upload image to mysql database using PDO?

From Dev

Image upload in a clustered tomcat, database or file system

From Dev

simple upload of image in database for sign up user

From Dev

how to upload image in database save in folder?

From Dev

Cant upload and store the image to the database by using php

From Dev

Multiple Image upload and save path to database

From Dev

How to upload an image and save it to database in Codeigniter?

Related Related

  1. 1

    Failed to upload an image

  2. 2

    PHP Upload image into database

  3. 3

    Upload image to SQL Database

  4. 4

    Image Upload into Database

  5. 5

    Upload Image with FileUpload and Stock in database

  6. 6

    Upload Name changing image to the database

  7. 7

    Image Upload to mysql database not working

  8. 8

    Image Upload In SQLite Database Android

  9. 9

    Vaadin upload image and store it to database

  10. 10

    Codeigniter image upload and path to database

  11. 11

    CodeIgniter: Upload Image to path and database

  12. 12

    Flutter Dio: Failed Upload Image to Server

  13. 13

    Failed to open stream? Image upload but are not echoing

  14. 14

    Remove image from content after failed upload

  15. 15

    Best implementation of: upload image file into database and read image from database

  16. 16

    Cant upload and store the image to the database by using php

  17. 17

    What is proper way to upload a image to a MySQL database?

  18. 18

    slim php framework image upload put database

  19. 19

    Upload image to file and information to mysql database

  20. 20

    Image upload in a clustered tomcat, database or file system

  21. 21

    Upload Image to Server and Store in MySQL Database

  22. 22

    How to upload an image and save it to database in Codeigniter?

  23. 23

    PHP Upload image to mysql database using PDO?

  24. 24

    Image upload in a clustered tomcat, database or file system

  25. 25

    simple upload of image in database for sign up user

  26. 26

    how to upload image in database save in folder?

  27. 27

    Cant upload and store the image to the database by using php

  28. 28

    Multiple Image upload and save path to database

  29. 29

    How to upload an image and save it to database in Codeigniter?

HotTag

Archive