0

I'm trying to upload an image into a MYSQL DB enter code herefrom a form in html by using PHP $_FILES but I dunno what I'm doing wrong, I'm new with PHP.

<form action="upload.php" enctype="multipart/form-data">
    Username: <input type="text" name="username" value=""><br>
    Password: <input type="password" name="password" value=""><br>
    Saga Title: <input type="text" name="saga_title"><br>
    Saga Description: <input type="text" name="saga_description"><br>
    Saga image (Max 4MB): <input type="file" name="saga_image"><br>
    <input type="submit" name="upload_saga" value="Upload Saga"><br>
    Episode Title: <input type="text" name="episode_title"><br>
    Episode Saga: <input type="text" name="episode_saga"><br>
    Episode Publication Date: <input type="text" name="episode_publication"><br>
    Episode Link: <input type="text" name="episode_link"><br>
    <input type="submit" name="upload_episode" value="Upload Episode">
</form>
<?php
    include('./database_connection.php');
    $connection = openConnection();

    if ($_GET['username'] != "" && $_GET['password'] != "") {
        echo $_FILES['saga_image']['tmp_name'];;
        $username = $_GET['username'];
        $password = $_GET['password'];

        if ($username == "user" && $password == "pwd") {
            if ($_GET['upload_saga'] != "") {
                $imagename = $_FILES['saga_image']['name'];
                $imagetmp=addslashes (file_get_contents($_FILES['saga_image']['tmp_name']));

                $query = 'INSERT INTO "saga" (title, description, image) VALUES ("' . $_GET['saga_title'] . '", "' . $_GET['saga_description'] . '", ' . $imagetmp . ')';
                echo $query;
                $result = $connection->query($query);

                if ($result === TRUE) {
                    echo '<p>Fatto</p>';
                }
            }       
    closeConnection($connection);
?>
Furious Mountain
  • 1,323
  • 3
  • 16
  • 44
HubHunter
  • 9
  • 2
  • Ok, the first thing that you need to go read about it hashed passwords. You must not pass passwords that are not encrypted in your code. Having said that, even though you can add the content of an image file into a field in the DB, you probably shouldn't do that. Check [this answer](https://stackoverflow.com/questions/6472233/can-i-store-images-in-mysql) for reference. Last, there are multiple reasons that it may not be working the way you intended but you need to show us what errors you're getting. – Paulo Hgo Dec 22 '19 at 17:28
  • First why you use user and pssw like that? second move file to your server then save link to db so you will call back when occur. – Simone Rossaini Dec 22 '19 at 17:37

0 Answers0