PHP MYSQL Upload Image With other data

67 views Asked by At

This is what it looks like. But when i press the submit button it wont upload the image. Is it possible to have 2 functions in one SUBMIT? It saves the other data in my database but the image is not uploaded nor it is in my database.

<?php

$con=mysqli_connect("localhost","root","","presyohan");
// Check connection
if (mysqli_connect_error())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

if(isset($_POST['submit']))
{
$prod_name = $_POST['prod_name'];
$prod_price = $_POST['prod_price'];
$prod_category = $_POST['prod_category'];
$sql="INSERT INTO products (prod_name, prod_price, prod_category)
 VALUES('$prod_name','$prod_price','$prod_category')";
$result=mysql_query($sql);

if ($con->query($sql) === TRUE) {
     session_start();
     $_SESSION['users'] = $rows['prod_name'];
     $_SESSION['id'] = $rows['user_id'];
header("Location: store-index.php");
die();
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}
//imageupload
  $filename = $_FILES['uploadfile']['name'];
  $filetmpname = $_FILES['uploadfile']['tmp_name'];
  $folder = 'images/products/';

  move_uploaded_file($filetmpname, $folder.$filename);

  $sqls = "INSERT INTO 'products' ('prod_img') VALUES ('$filename')";
  $qry = mysqli_query($con, $sqls);
  if ($qry) {
   echo 'header("Location: store-index.php")';
  }

$con->close();


}
?>
 <form class="form" action="add-prod.php" method="post" enctype="multipart/form-data"> 
       

        <div class="upload-btn-wrapper">
            <label for="file-upload" class="custom-file-upload">
              Product Image  <i class="fas fa-cloud-upload-alt"></i> 
            </label>
              <input id="file-upload" type="file" name="uploadfile" />
            
           
          </div>   
        <div class="form__group">          
          <button class="btn" type="submit" name="submit">ADD</button>
        </div>
         
        
    </form>

enter image description here

0

There are 0 answers