63 lines
2.6 KiB
PHP
63 lines
2.6 KiB
PHP
<?php
|
|
include "../ConnectDB.php";
|
|
|
|
// Check if the form is submitted
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
// Get the submitted form data
|
|
$formData = $_POST['data'];
|
|
|
|
// Process each item's form data
|
|
foreach ($formData as $itemName => $itemData) {
|
|
$id = $itemData['id'];
|
|
$name = $itemData['name'];
|
|
$simpledesc = $itemData['simpledesc'];
|
|
$fulldesc = $itemData['fulldesc'];
|
|
$quantities = $itemData['quantities'];
|
|
$buyer_price = $itemData['buyer_price'];
|
|
$seller_price = $itemData['seller_price'];
|
|
$buyer_availability = $itemData['buyer_availability'];
|
|
$seller_availability = $itemData['seller_availability'];
|
|
|
|
if($buyer_price < $seller_price){
|
|
echo "<br><br><br><br><br><br>";
|
|
echo "<h1>The buyer price of $id cannot be lower than its seller price!</h1>";
|
|
echo "<script type='text/javascript'>
|
|
setTimeout(function() {window.location.href = './edit.php';}, 1000);
|
|
</script>";
|
|
exit();
|
|
}
|
|
|
|
// Prepare and execute the update query
|
|
$stmt = mysqli_prepare($conn, "UPDATE inventory SET name=?, simpledesc=?, fulldesc=?, quantities=?, buyer_price=?, seller_price=?, buyer_availability=?, seller_availability=? WHERE name=?");
|
|
mysqli_stmt_bind_param($stmt, "sssssssss", $name, $simpledesc, $fulldesc, $quantities, $buyer_price, $seller_price, $buyer_availability, $seller_availability, $id);
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
$sql_buyer_name = "ALTER TABLE `buyer` CHANGE `$id` `$name` INT(11) NOT NULL DEFAULT '0'";
|
|
$res_1 = mysqli_query($conn, $sql_buyer_name);
|
|
|
|
$sql_seller_name = "ALTER TABLE `seller` CHANGE `$id` `$name` INT(11) NOT NULL DEFAULT '0'";
|
|
$res_2 = mysqli_query($conn, $sql_seller_name);
|
|
|
|
// Check if the update was successful
|
|
if (mysqli_stmt_affected_rows($stmt) > 0 && $res_1 && $res_2) {
|
|
//echo "Data updated successfully.";
|
|
echo "<script type='text/javascript'>
|
|
window.location.href = './interfaces/success.php';
|
|
</script>";
|
|
} else {
|
|
if(mysqli_stmt_error($stmt) || !$res_1 || !$res_2){
|
|
echo "<script type='text/javascript'>
|
|
alert('Failed to update data.');
|
|
window.location.href = './edit.php';
|
|
</script>";
|
|
}
|
|
}
|
|
echo "<script type='text/javascript'>
|
|
window.location.href = './interfaces/success.php';
|
|
</script>";
|
|
|
|
// Close the statement
|
|
mysqli_stmt_close($stmt);
|
|
}
|
|
}
|
|
?>
|