Skip to content Skip to sidebar Skip to footer

Auto Submit Is Not Posting Data To Database

I am trying to post a file into a Blob. I have created a HTML form that automatically posts when A file is selected:
attribute. This attribute is required to upload files.

It'll look like:

<form id="target" method="post" enctype='multipart/form-data' name="frmImage" class="frmImageUpload" action="./post.php">  
  <div id="pic1">
    <input type="file" name="userfile"id="userfile" class="userfile"/>
  </div>
</form>

I recommend you using move_uploaded_file. See more.

Solution 2:

According to your comment, you are getting undefined index notice due to multipart/form-data,

You need to use enctype="multipart/form-data" in your <form> as:

<form id="target" method="post" name="frmImage"class="frmImageUpload" action="./post.php" enctype="multipart/form-data">  

Second, you need to define $fileName as $fileName = ''; at top level declaration, otherwise you will get another undefined variable notice

You need to declare it before this line:

if(isset($_POST['userfile']) && $_FILES['userfile']['size'] > 0) {

as:

$fileName = '';
if(isset($_POST['userfile']) && $_FILES['userfile']['size'] > 0) {

Third, mysql_* is deprecated extension and closed in PHP7, i suggest you to use mysqli_* or PDO.

Fourth, you code is wide open for SQL injection, preventing for SQL injection, you can use PDO.

Fifth, and dont know what is it? $_SESSION['user_id'];

Some useful links:

How can I prevent SQL injection in PHP?

Are PDO prepared statements sufficient to prevent SQL injection?

Post a Comment for "Auto Submit Is Not Posting Data To Database"