PHP Code:
<?php
####################################################################
## Getting posted $Variables #######################################
####################################################################
// I highly recommend that you change your form variables to the ones
// listed in the $fieldArray below, or change the variables names in the
// $fieldArray AND the query to the names that you have on your
// form. It helps keep things cleaner and there is less maintenance and
// headache trying to figure out where a value changes variable names.
$fieldArray = ( name,
id,
sku,
short_description,
product_group,
category,
sub_category,
product_price,
dealer_price,
quanitity,
small_picture,
large_picture,
detailed_description,
weight,
special,
taxable,
view,
add_to_cart,
spic_original_file,
lpic_original_file,
spic_path,
lpic_path,
Update );
// The foreach() loop tests each $_POST[] variable for a value and assigns
// it to its coresponding variable.
// if there is no value in the $_POST[] variable, then the coresponding
// variable is set to "" (no value)
foreach( $fieldArray as $fieldValue )
{
$$fieldValue = isset( $_POST[$$fieldValue] ) ? $_POST[$$fieldValue] : '';
}
####################################################################
## Updating the Item ###############################################
####################################################################
// Any field that accepts a NUMERIC value only needs to have the
// variable that it is being set to bare of single quotes.
// Just like you did with $id and the ID field
if ( $submit == "Update" )
{
$sql = "UPDATE Inventory_A
SET
Item_Name = '$name',
SKU = '$sku',
Short_Description = '$short_description',
Product_Group = '$product_group',
Category = '$category',
Sub_Category = '$sub_category',
Product_Price = '$product_price',
Dealer_Price = '$dealer_price',
Quantity = '$quantity',
Small_Picture = '$small_picture',
Large_Picture = '$large_picture',
Detailed_Description = '$detailed_description',
Weight = '$weight',
Special = '$special',
Taxable = '$taxable',
View = '$view',
Add_To_Cart = '$add_to_cart',
spic_original_file = '$spic_original_file',
lpic_original_file = '$lpic_original_file',
spic_path = '$spic_path',
lpic_path = '$lpic_path'
WHERE
ID = $id
";
if ( mysql_query( $sql ))
echo "Item $name has been succesfully updated.<br>";
}
echo "$name<br>";
echo "$id<br>";
echo "$submit";
?>
If you have any questions about this, let me know!
Bookmarks