$value) {
//echo $key.' '.$value.'KEY:
';
if(isset($_POST[$key]) && $_POST[$key] == 'on') {
//echo $_POST[$key].": ".$key." ".$_POST[$key.'-value']."
";
if(!empty($_POST[$key.'-value'])) {
$product_information[$key] = $_POST[$key.'-value'];
}
else {
$product_information[$key] = NULL;
}
}
else if(isset($_POST[$key]) && (!empty($value) || $value == '0')) {
$product_information[$key] = $value;
}
}
foreach($_FILES['images']['name'] as $key => $name) {
if(!empty($name)) {
$tmpName = $_FILES['images']['tmp_name'][$key];
$fileName = basename($name);
$targetFilePath = $targetDirectory . $fileName;
if (move_uploaded_file($tmpName, $targetFilePath)) {
echo "File $fileName uploaded successfully.
";
$product_information['image'.$key+1] = "'$targetFilePath'";
} else {
$product_information['image'.$key+1] = NULL;
echo "Failed to upload $fileName.
";
}
}
}
$stmt = $conn->prepare("INSERT INTO products (
name,
price,
discount,
in_stock,
category,
description,
image1,
image2,
image3,
image4,
brand,
series,
model_number,
weight,
dimensions,
color,
manufactuer,
origin,
firstDate,
energy,
volts,
memorySpeed,
usb3,
usb2,
processorBrand,
numProcess,
typeMem,
HardDD,
HardPlat,
HardFlash,
HardInterface,
gpuRAM,
motherboardRam,
motherboardTYPE,
screenSize,
screenRes,
screenMax
)
VALUES (
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?
);
"
);
if($product_information['in_stock'] == "true") {
$product_information['in_stock'] = 1;
}
else {
$product_information['in_stock'] = 0;
}
$stmt->bind_param(
"ssdissssssssssssssssiiiisisssssiissss",
$product_information["name"], $product_information["price"], $product_information["discount"], $product_information["in_stock"],
$product_information["category"], $product_information["description"], $product_information["image1"], $product_information["image2"],
$product_information["image3"], $product_information["image4"], $product_information["brand"], $product_information["series"],
$product_information["model_number"], $product_information["weight"], $product_information["dimensions"], $product_information["color"],
$product_information["manufactuer"], $product_information["origin"], $product_information["firstDate"],
$product_information["energy"], $product_information["volts"], $product_information["memorySpeed"], $product_information["usb3"], $product_information["usb2"],
$product_information["processorBrand"], $product_information["numProcess"],
$product_information["typeMem"], $product_information["HardDD"], $product_information["HardPlat"], $product_information["HardFlash"],
$product_information["HardInterface"], $product_information["gpuRAM"],
$product_information["motherboardRAM"], $product_information["motherboardTYPE"], $product_information["screenSize"], $product_information["screenRes"],
$product_information["screenMax"]
);
if ($stmt->execute()) {
echo "
Data updated successfully!
"; } else { echo "Error updating data: " . $conn->error . "
"; } $conn->close(); }