I have only just started learning Php so if this is laughable then theres the reason...thanks for your help Richard
<?php
include("header.inc");
/ FUNCTIONS /
function do_upload($userfile,$image_name) {
$file = basename($userfile);
$img_data=getimagesize($userfile);
$src_w=$img_data[0];
$src_h=$img_data[1];
$src_img2=ImageCreateFromJPEG($userfile) or die ("Cannot open source");
$new_wl = 360;
$new_hl = 240;
$dst_img2=imagecreate($new_wl,$new_hl);
imagecopyresized($dst_img2,$src_img2, 0, 0, 0, 0, $new_wl, $new_hl, $src_w, $src_h);
chdir("../stock");
if ( file_exists($image_name) )
{
unlink($image_name);
}
imagejpeg($dst_img2,$image_name);
ImageDestroy($src_img2);
ImageDestroy($dst_img2);
}
function do_upload_thumb($userfile,$image_name) {
$file = basename($userfile);
$img_data=getimagesize($userfile);
$src_w=$img_data[0];
$src_h=$img_data[1];
$src_img=ImageCreateFromJPEG($userfile) or die ("Cannot open source");
$new_w =180;
$new_h =120;
$dst_img=imagecreate($new_w,$new_h);
$dst_img_large=imagecreate($new_wl,$new_hl);
imagecopyresized($dst_img,$src_img, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src_h);
chdir("thumbnails");
if ( file_exists($image_name) )
{
unlink($image_name);
}
imagejpeg($dst_img,$image_name);
ImageDestroy($src_img);
ImageDestroy($dst_img);
}
function do_update($category,$subcategory,$name,$description,$price,$image_name){
$db = mysql_connect("localhost", "root");
mysql_select_db("brandnew",$db);
$sql = "UPDATE antiques SET category='$category', subcategory='$subcategory', name='$name', description='$description', price='$price',image_name='$image_name' WHERE id='$id'";
$result = mysql_query($sql);
echo "Thank you! Information updated.\n<br><br>";
echo "<a href=\"antiquedealer.php\"><u>BACK TO MAINPAGE</u></a>";
}
/ END OF FUNCTIONS /
/ SUBMITTING FORM /
if ( (isset($submit)) && (isset($id)) ) {
if (($category == "") && ($categoryexist == "Select Category")){
echo "Please fill in the category Field";
exit; }
elseif (($category != "") && ($categoryexist != "Select Category")){
echo "You have entered two Categories, please use only one";
exit; }
elseif ($category != "") {
$category = $category;
}
elseif (($categoryexist != "") && ($categoryexist != "Select Category")){
$category = $categoryexist;
}
if (($subcategory == "") && ($subcatexist == "Select Subcategory")){
echo "Please fill in the Subcategory Field";
exit;
}
elseif (($subcategory != "") && ($subcatexist != "Select Subcategory")){
echo "You have entered two Subcategories, please use only one";
exit;
}
elseif ($subcategory != "") {
$subcategory = $subcategory;
}
elseif (($subcatexist != "") && ($subcatexist != "Select Subcategory")){
$subcategory = $subcatexist;
}
if ($name == "") {
echo "Please fill in the Name field";
exit;
}
if ($description == "") {
echo "Please fill in the description field";
exit;
}
if ($price == "") {
echo "Please enter a Price for your item";
exit;
}
if ($image_name == "") {
echo "Please enter a name for your image";
exit;
}
if (($userfile != "") && ($image_name != "")){
$image_name = "$image_name.jpg";
do_upload($userfile,$image_name);
do_upload_thumb($userfile,$image_name);
}
do_update($category,$subcategory,$name,$description,$price,$image_name);
}
else {
$db = mysql_connect("localhost", "root");
mysql_select_db("brandnew",$db);
$sql = "SELECT * FROM antiques WHERE id=$id";
$resulted = mysql_query($sql);
$myrows = mysql_fetch_array($resulted);
?>
<table width="500" align="center" valign="top" bgcolor="#A49786">
<form enctype="multipart/form-data" method="post" action="<? $PHP_SELF ?>">
<input type=hidden name="id" value="<?php echo $myrows["id"] ?>">
<tr><td width="500" bgcolor="#A49786" height="35" colspan="2" align="right"><a href="javascript:opensmall('help.html')">HELP</a></td></tr>
<tr>
<td align="left" width="250">Category</td><td align="left" width="250">Create New Category</td></tr>
<tr><td align="left" valign="top">
<?php
/ CATEGORY DROPDOWN /
echo "<select name=\"categoryexist\">
<option>Select Category</option>";
$results = mysql_query("SELECT DISTINCT category FROM antiques",$db);
while ($myrow = mysql_fetch_array($results)) {
print ("<option value=\"$myrow[category]\">$myrow[category]");
}
echo "</select>";
/ END CATEGORY DROPDOWN /
?>
</td>
<td valign="top" align="left" width="250">
<input type="text" name="category" value="<?php echo $myrows["category"] ?>" size="30">
</td></tr>
<tr>
<td align="left">SubCategory</td><td align="left">Create New SubCategory</td></tr>
<tr><td width="250" align="left" valign="top">
<?php
/ SUBCATEGORY DROPDOWN /
echo "<select name=\"subcatexist\">
<option selected>Select Subcategory</option>";
$result = mysql_query("SELECT DISTINCT subcategory FROM antiques",$db);
while ($myrow = mysql_fetch_array($result)) {
print ("<option value=\"$myrow[subcategory]\">$myrow[subcategory]");
}
echo "</select>";
/ END SUBCATEGORY DROPDOWN /
?>
</td><tr>
<td valign="top"><input type="text" name="subcategory" value="<?php echo $myrows["subcategory"] ?>"size="30">
</td></tr>
<tr>
<td colspan="2" width="500" align="left" valign="top">Item Name</td></tr>
<tr>
<td colspan="2" valign="top" align="left"><input type="Text" name="name" value="<?php echo $myrows["name"] ?>" size="30">
</td>
</tr>
<tr><td colspan="2" width="500">Description</td></tr>
<tr><td width="500" colspan="2">
<textarea name="description" rows="7" cols="50"><?php echo $myrows["description"] ?></textarea></td>
</tr>
<tr><td colspan="2" width="500">Price<br>
<input type="Text" name="price" value="<?php echo $myrows["price"] ?>" size="35">
</td></tr>
<tr>
<td colspan="2" width="500" align="left">Image File</td></tr>
<tr><td width="500" colspan="2">
<input type="File" name="userfile" size="35" maxlength="255"><br></td></tr>
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000">
<tr>
<td colspan="2" width="500">Image Name</td></tr>
<tr><td colspan="2" width="500">
<input type="Text" name="image_name" value="<?php echo $myrows["image_name"] ?>" size="35">
<INPUT TYPE="submit" name="submit" VALUE="Enter Information"></td>
</tr>
</table>
</FORM>
}
</body>