[f9c482b] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | require 'connect.php';
|
---|
| 4 |
|
---|
| 5 | if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
---|
| 6 |
|
---|
| 7 | $product_information = array();
|
---|
| 8 | $targetDirectory = "./UPLOADED_IMAGES/";
|
---|
| 9 |
|
---|
| 10 | foreach ($_POST as $key => $value) {
|
---|
| 11 | //echo $key.' '.$value.'KEY: <br>';
|
---|
| 12 | if(isset($_POST[$key]) && $_POST[$key] == 'on') {
|
---|
| 13 |
|
---|
| 14 | //echo $_POST[$key].": ".$key." ".$_POST[$key.'-value']."<br>";
|
---|
| 15 | if(!empty($_POST[$key.'-value'])) {
|
---|
| 16 | $product_information[$key] = $_POST[$key.'-value'];
|
---|
| 17 | }
|
---|
| 18 | else {
|
---|
| 19 | $product_information[$key] = NULL;
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 | else if(isset($_POST[$key]) && (!empty($value) || $value == '0')) {
|
---|
| 23 | $product_information[$key] = $value;
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | foreach($_FILES['images']['name'] as $key => $name) {
|
---|
| 28 | if(!empty($name)) {
|
---|
| 29 | $tmpName = $_FILES['images']['tmp_name'][$key];
|
---|
| 30 | $fileName = basename($name);
|
---|
| 31 |
|
---|
| 32 | $targetFilePath = $targetDirectory . $fileName;
|
---|
| 33 |
|
---|
| 34 | if (move_uploaded_file($tmpName, $targetFilePath)) {
|
---|
| 35 | echo "File $fileName uploaded successfully.<br>";
|
---|
| 36 | $product_information['image'.$key+1] = "'$targetFilePath'";
|
---|
| 37 | } else {
|
---|
| 38 | $product_information['image'.$key+1] = NULL;
|
---|
| 39 | echo "Failed to upload $fileName.<br>";
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | $stmt = $conn->prepare("INSERT INTO products (
|
---|
| 45 | name,
|
---|
| 46 | price,
|
---|
| 47 | discount,
|
---|
| 48 | in_stock,
|
---|
| 49 | category,
|
---|
| 50 | description,
|
---|
| 51 | image1,
|
---|
| 52 | image2,
|
---|
| 53 | image3,
|
---|
| 54 | image4,
|
---|
| 55 | brand,
|
---|
| 56 | series,
|
---|
| 57 | model_number,
|
---|
| 58 | weight,
|
---|
| 59 | dimensions,
|
---|
| 60 | color,
|
---|
| 61 | manufactuer,
|
---|
| 62 | origin,
|
---|
| 63 | firstDate,
|
---|
| 64 | energy,
|
---|
| 65 | volts,
|
---|
| 66 | memorySpeed,
|
---|
| 67 | usb3,
|
---|
| 68 | usb2,
|
---|
| 69 | processorBrand,
|
---|
| 70 | numProcess,
|
---|
| 71 | typeMem,
|
---|
| 72 | HardDD,
|
---|
| 73 | HardPlat,
|
---|
| 74 | HardFlash,
|
---|
| 75 | HardInterface,
|
---|
| 76 | gpuRAM,
|
---|
| 77 | motherboardRam,
|
---|
| 78 | motherboardTYPE,
|
---|
| 79 | screenSize,
|
---|
| 80 | screenRes,
|
---|
| 81 | screenMax
|
---|
| 82 | )
|
---|
| 83 |
|
---|
| 84 | VALUES (
|
---|
| 85 | ?,
|
---|
| 86 | ?,
|
---|
| 87 | ?,
|
---|
| 88 | ?,
|
---|
| 89 | ?,
|
---|
| 90 | ?,
|
---|
| 91 | ?,
|
---|
| 92 | ?,
|
---|
| 93 | ?,
|
---|
| 94 | ?,
|
---|
| 95 | ?,
|
---|
| 96 | ?,
|
---|
| 97 | ?,
|
---|
| 98 | ?,
|
---|
| 99 | ?,
|
---|
| 100 | ?,
|
---|
| 101 | ?,
|
---|
| 102 | ?,
|
---|
| 103 | ?,
|
---|
| 104 | ?,
|
---|
| 105 | ?,
|
---|
| 106 | ?,
|
---|
| 107 | ?,
|
---|
| 108 | ?,
|
---|
| 109 | ?,
|
---|
| 110 | ?,
|
---|
| 111 | ?,
|
---|
| 112 | ?,
|
---|
| 113 | ?,
|
---|
| 114 | ?,
|
---|
| 115 | ?,
|
---|
| 116 | ?,
|
---|
| 117 | ?,
|
---|
| 118 | ?,
|
---|
| 119 | ?,
|
---|
| 120 | ?,
|
---|
| 121 | ?
|
---|
| 122 | );
|
---|
| 123 | "
|
---|
| 124 | );
|
---|
| 125 |
|
---|
| 126 | if($product_information['in_stock'] == "true") {
|
---|
| 127 | $product_information['in_stock'] = 1;
|
---|
| 128 | }
|
---|
| 129 | else {
|
---|
| 130 | $product_information['in_stock'] = 0;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | $stmt->bind_param(
|
---|
| 134 | "ssdissssssssssssssssiiiisisssssiissss",
|
---|
| 135 | $product_information["name"], $product_information["price"], $product_information["discount"], $product_information["in_stock"],
|
---|
| 136 | $product_information["category"], $product_information["description"], $product_information["image1"], $product_information["image2"],
|
---|
| 137 | $product_information["image3"], $product_information["image4"], $product_information["brand"], $product_information["series"],
|
---|
| 138 | $product_information["model_number"], $product_information["weight"], $product_information["dimensions"], $product_information["color"],
|
---|
| 139 | $product_information["manufactuer"], $product_information["origin"], $product_information["firstDate"],
|
---|
| 140 | $product_information["energy"], $product_information["volts"], $product_information["memorySpeed"], $product_information["usb3"], $product_information["usb2"],
|
---|
| 141 | $product_information["processorBrand"], $product_information["numProcess"],
|
---|
| 142 | $product_information["typeMem"], $product_information["HardDD"], $product_information["HardPlat"], $product_information["HardFlash"],
|
---|
| 143 | $product_information["HardInterface"], $product_information["gpuRAM"],
|
---|
| 144 | $product_information["motherboardRAM"], $product_information["motherboardTYPE"], $product_information["screenSize"], $product_information["screenRes"],
|
---|
| 145 | $product_information["screenMax"]
|
---|
| 146 | );
|
---|
| 147 |
|
---|
| 148 | if ($stmt->execute()) {
|
---|
| 149 | echo "<p><font color='green'>Data updated successfully!</font></p>";
|
---|
| 150 | } else {
|
---|
| 151 | echo "<p><font color='red'>Error updating data: " . $conn->error . "</font></p>";
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | $conn->close();
|
---|
| 155 | }
|
---|