A
Anonymous
Guest
i'm using this upload code below.
i am a student working on an ecommerce project
i have an ecommerc website and an admin on the page that i have, i'm working on the admin part at the moment.
i want the admin to enter info into all of the fields that are provided such as the item name, item description, and item price, and item image.
here is the site that i'm working on for an example
http://www.wootenmedia.com/wootenmusic7/admintest/add3_1_3.php
i would like the name to be inserted into the datbase in order for the image to show up on the ecommerc website on the products pages here is my ecommerce site i have
http://www.wootenmedia.com/wootenmusic7/guitars.php
can anyone help me out in getting the image name, which is being uploaded, to the database so that the image will show up on the products page of the ecommmerce website any help would be appreciated.
thanks
this is the code that i'm using for uploading the image and inserting the image into the database:
i am a student working on an ecommerce project
i have an ecommerc website and an admin on the page that i have, i'm working on the admin part at the moment.
i want the admin to enter info into all of the fields that are provided such as the item name, item description, and item price, and item image.
here is the site that i'm working on for an example
http://www.wootenmedia.com/wootenmusic7/admintest/add3_1_3.php
i would like the name to be inserted into the datbase in order for the image to show up on the ecommerc website on the products pages here is my ecommerce site i have
http://www.wootenmedia.com/wootenmusic7/guitars.php
can anyone help me out in getting the image name, which is being uploaded, to the database so that the image will show up on the products page of the ecommmerce website any help would be appreciated.
thanks
this is the code that i'm using for uploading the image and inserting the image into the database:
Code:
<?
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");
?>
<?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 value="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>
<?
//START DB Stuff Here////////////////
// specify the directory where the uploaded file should end up
$path = "/home/username/public_html/wootenmusic7/p_imgs/";
// specify the filetypes allowed
$allowed = array('image/gif','image/pjpeg','image/jpeg','image/png');
// specify the max filesize in bytes
$max_size = 200000;
if(isset($_FILES['txtItemImage']))
{
if(is_uploaded_file($_FILES['txtItemImage']['tmp_name']))
{
if($_FILES['txtItemImage']['size'] < $max_size)
{
if(in_array($_FILES['txtItemImage']['type'],$allowed))
{
if(!file_exists($path . $_FILES['txtItemImage']['name']))
{
if(move_uploaded_file($_FILES['ItemImage']['tmp_name'],$path.$_FILES['txtItemImage']['name']))
{
$html_output = 'Upload sucessful!<br>';
$html_output .= 'File Name: '.$_FILES['txtItemImage']['name'].'<br>';
$html_output .= 'File Size: '.$_FILES['txtItemImage']['size'].' bytes<br>';
$html_output .= 'File Type: '.$_FILES['txtItemImage']['type'].'<br>';
$image = $_FILES['txtItemImage']['name'] ;
}else{
$html_output = 'Upload failed!<br>';
if(!is_writeable($path))
{
//$html_output = 'The Directory "'.$path.'" must be writeable!<br>';
}else{
$html_output = 'an unknown error ocurred.<br>';
}
}
}else{
$html_output = 'The file already exists<br>';
}
}else{
$html_output = 'Wrong file type<br>';
}
}else{
$html_output = 'The file is too big<br>';
}
}
}else{
$html_output = '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">';
$html_output .= '<input type="file" name="txtItemImage">';
$html_output .= '<input type="submit" name="submit" value="upload"><input type="Reset" />';
$html_output .= '</form>';
}
echo '<html><head><title>Uploader</title></head><body>';
echo $html_output;
echo '</body></html>';
$html_output = $_POST['submit'];
if(isset($html_output)){
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 = $_FILES['txtItemImage']['name'];
echo "$theSQL";
$theSQL = "insert into items (prodItems, catid, itemName, itemDesc, itemPrice, ItemImage)";
$theSQL = $theSQL . " values ('$txtprodItems', '$txtCatID', '$txtItemName', '$txtItemDesc', '$txtItemPrice', '$txtItemImage')";
$result = mysql_query($theSQL);
echo "$theSQL";
}else{
echo "did not insert any image into database";
}
?>