i'm a student working on an ecommerce website project with an administration section.
i have the ecommerce website done, now i'm working on the administration section for the ecommerce website.
the section i'm working on now is an add items page where the admin can input text into the form and submit it and the information will be inserted into the database and that information will be displayed on the products page of the ecommerce website.
i got most of the form working as far as inserting item name, description, and price. all that i need help with is getting the upload part of the form to work. i have the upload script in my code, but it doesn't seem to be uploading images into the correct folder and it doesn't seem to display the images that are being uploaded.
can anyone help me out with this script in getting this to work. i would like it to upload the image to a folder and after the image is uploaded, i would like that image to be displayed on the products page of my ecommerce website.
can anyone help me out in any kind of way so that this will work and the images will be displayed?
any help would be greatly appreciated.
thanks
here's the admin add page that i'm working on:
http://www.wootenmedia.com/admintest/new_add3_1.php
here's the ecommerce site that i have:
http://www.wootenmedia.com/wootenmusic7/guitars.php
here's my code that i have so far:
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<META HTTP-EQUIV='Pragma' CONTENT='no-cache' />
<META HTTP-EQUIV='Cache-Control' CONTENT='no-cache' />
</head>
<body>
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post" ENCTYPE="multipart/form-data">
Choose a product category <br>
<select name="txtCatID" id="select">
<option value="0" SELECTED>0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br>
Choose product items to add to your product pages <br>
<input type="hidden" name="<?echo '$txtCatID';?>">
<select name="txtprodItems" id="select">
<option alue="Guitars" SELECTED>Guitars</option>
<option value="Drums">Drums</option>
<option value="Amps">Amps</option>
<option value="Books">Books</option>
</select><br>
item name<br>
<input type="text" name="txtItemName"><br>
item description<br>
<input type="text" name="txtItemDesc"><br>
item price<br>
<input type="text" name="txtItemPrice"><br>
upload image<br>
<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="800000">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="1">
<input type="file" name="txtItemImage"><br>
<input type="submit" name="submit" value="submit"><input type="Reset">
<?
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
?>
<?
$uploaddir = '/home/username/public_html/wootenmusic7/p_imgs/';
$uploadfile = $uploaddir. $_FILES['txtItemImage']['name'];
$imagesize = getimagesize($_FILES['txtItemImage']['tmp_name']);
if($_POST["action"] == 1){
if($_FILES['txtItemImage']['name'] =="none" || $_FILES['txtItemImage']['name'] == ""){
#error message here for no file uploaded
#exit; or redirect
echo "NO FILE UPLOADED";
}
if($imagesize == 1 || $imagesize == 2 || $imagesize == 3){
if(move_uploaded_file($_FILES['txtItemImage']['tmp_name'], $uploadfile)){
echo "File Uploaded Successfully<br />";
echo "File Name: ".$_FILES['txtItemImage']['name']."<br />";
echo "File Type: ".$_FILES['txtItemImage']['type']."<br />";
echo "File Size: ".$_FILES['txtItemImage']['size']." kb<br />";
} else {
echo "FAILED";
}
} else {
#error message here for no file uploaded
#exit; or redirect
echo "No File Uploaded";
}
##START DB Stuff Here#############
$submit = $_POST['submit'];
if(isset($submit)){
include("db2.php");
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$txtCatID = $_POST['txtCatID'];
$txtprodItems = $_POST['txtprodItems'];
$txtItemName = $_POST['txtItemName'];
$txtItemDesc = $_POST['txtItemDesc'];
$txtItemPrice = $_POST['txtItemPrice'];
$txtItemImage = $_POST['txtItemImage'];
$theSQL = "insert into items (prodItems, catid, itemName, itemDesc, itemPrice, ItemImage)";
$theSQL = $theSQL . " values ('$txtprodItems', '$txtCatID', '$txtItemName', '$txtItemDesc', '$txtItemPrice', '{$_FILES['ItemImage']['name']}')";
$result = mysql_query($theSQL);
echo "<br><br>";
echo "Thanks, the items have been added to category<br><br>";
echo "
The items that you have add to the category are: <br>
Product Items: $txtprodItems <br>
Cat Id: $txtCatID <br>
Item Description: $txtItemDesc <br>
Item Price: $ $txtItemPrice <br>
Item Image: $txtItemImage
";
}
else
{
echo "<br><br><br>You Have To Enter In All Information Before Results Can Show";
}
##END DB Stuff Here#############
} else {
#redirect them back to upload form
echo "must enter information into form";
}
?>
</body>
</html>