Hi there,
I am trying to upload to images for my product site.
so far form is not functioning, i get error.
can you please help me with this one ?
Is there a better way to do this ?
my code:
<?php
include("../includes/db.conf.php");
include("../includes/connect.inc.php");
include ("../includes/functions.inc.php");
echo "<html><body bgcolor='#cccccc'><center>";
if (isset($_POST['submit'])){
$folder = "../images/";
@copy("$image" , "$folder/$image_name");
thumbnail("../images/","../images/",$image_name,100);
$uploadDir = 'productimages/';
$uploadFile = $uploadDir . $_FILES['userfile']['name'];
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile))
{
$queryn="INSERT into products set name='$_POST[pname]', photo='$image_name', description='$_POST[description]', price='$_POST[price]', category='$_POST[category]', quantity='$_POST[quantity]',photobig='$uploadFile'";
$mysqlresultn = mysql_query($queryn);
}
else
{
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
echo "New Product Added<br>";
echo mysql_error();
}
echo "<h3>Add New Product</h3>";
echo "<form action='addproduct.php' method='post' enctype='multipart/form-data'> ";
echo "<table>";
echo "<tr><td>Product Name</td>";
echo "<td><input name='pname' type='text' size='25' /></td></tr>";
echo "<tr><td colspan=2>Description</td></tr>";
echo "<tr><td colspan=2><textarea name='description' cols='30' rows='5'></textarea></td></tr>";
echo "<tr><td>Price</td>";
echo "<td><input type='text' name='price'></td></tr>";
echo "<tr><td>Photo</td>";
echo "<td><input type='file' name='image'></td></tr>";
echo "<tr><td>Photo big</td>";
echo "<td><input type='file' name='userfile'></td></tr>";
echo "<tr><td>Category</td>";
echo "<td><select name='category'>";
$query = "SELECT * from productcategories ";
$mysqlresult = mysql_query($query);
while($row = mysql_fetch_array($mysqlresult)){
echo "<option value='$row[id]'>$row[name]</option>";
}
echo "<select></td></tr>";
echo "<tr><td>Quantity</td>";
echo "<td><input type='text' name='quantity'></td></tr>";
echo "<tr><td colspan=2><input type='submit' name='submit' value='Submit'></td></tr>";
echo "</table>";
echo "</body></html>";
?>
Thank you,