-4

The code is not able to insert an image into the database because it does not go past the if statement. When i run the application, i always get "Please Insert a valid image". I don't get any errors in the code. Please your help will be appreciated.

    <form action="uploadtest.php" method="POST" ectype="multipath/form-data">
        <label>Picture:</label><input type="file" name="image">
        <input type="submit" name="submit" value="Add Record">

  <?php
   mysql_connect("localhost", "root", "");
   mysql_select_db("testlab");

    //file properties

    if(empty($_FILES) || !isset($_FILES['image']))
    {   
    echo "Please Insert a valid image";

    }//end of if statement

    else
    {   
       $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
       $image_name = addslashes($_FILES['image']['name']);
       $image_size = getimagesize($_FILES['image']['tmp_name']);
          if($image_size==FALSE)
         echo "This is not an image.";
          else
         {
        mysql_query("INSERT into testimage VALUES('','$image_name','$image'");
        echo "Image Successfully inserted into the Database";
         }
    }//end of else statement
?>
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • 2
    [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Phil May 01 '14 at 05:35
  • 1
    `addslashes()` eh? That's even worse than `mysql_real_escape_string()` which is deprecated. Might want to check the published date on whatever ancient tutorial you're following and think about trying out some more *recent* resources – Phil May 01 '14 at 05:38

2 Answers2

1

You have a typo in your HTML - it should be enctype="multipart/form-data", not 'ectype' and 'multipath'.

sevenseacat
  • 24,699
  • 6
  • 63
  • 88
  • its now working after changing it to enctype="multipart/form-data" Thanks so much for your help, i really appreciate it. – user3591678 May 01 '14 at 09:26
0

Change ectype="..." to enctype="..." (you are missing the 'n').

GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59
ashutosh
  • 81
  • 7
  • its now working after changing it to enctype="multipart/form-data" Thanks so much for your help, i really appreciate it. – user3591678 May 01 '14 at 09:27