I have set up the html and javascript here:
http://jsbin.com/aNiTixA/1/edit?html,css,output
Here is my php code:
<?php
$con=mysqli_connect("localhost","up637415_cms","up637415_cms","up637415_cms");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO products (prod_title, prod_category, prod_quantity, prod_description, prod_img)
VALUES
('$_POST[prod_title]','$_POST[prod_category]','$_POST[prod_quantity]','$_POST[prod_description]','$_POST[file1]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
What I want to do is store the path of the recently uploaded image in the MYSQL database in the column named 'prod_img' so that it can be displayed on the front end of the site. I am not sure how to get the path from the image after its uploaded and post it to the database when the submit button has been pressed.
FILE
is accessed through$_FILES[]
not$_POST
, #2, The file must bemoved somewhere
otherwise the location will be a temporary one and is not guaranteed to exist forever, #3 - thank you for using MySQLI. – Ohgodwhy 21 hours ago