Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why is the quantity not saving when i run my save.php . Whenever i submit or press enter it doesn't submit to the database. prepare

Why is the quantity not saving when i run my save.php. Whenever i submit or press enter it doesn't submit to the database.
prepare("SELECT user_id, branch FROM users WHERE username =?");
$userQuery->bind_param("s", $username);
$userQuery->execute();
$userResult = $userQuery->get_result();
$userRow = $userResult->fetch_assoc();
$userId = $userRow['user_id'];
$userBranch = $userRow['branch'];
$userLevel = $_SESSION['level']; // Fetch user level from session
foreach ($ids as $id){
$sizes = $_POST['size'][$id]??[];
$sizesString = implode(',', $sizes);
$quantity = $_POST['quantity'][$id]??0;
$branch = $userBranch; // Use the branch from the user info
if ($userLevel =='2'|| $userLevel =='3'){
// Update only the quantity
$orderStmt = $conn->prepare("
INSERT INTO `order`(branch, user_id, item_id, quantity, size)
VALUES (?,?,?,?,?)
ON DUPLICATE KEY UPDATE
quantity = VALUES(quantity)
");
} elseif ($userLevel =='1'){
// Update only the size
$orderStmt = $conn->prepare("
INSERT INTO `order`(branch, user_id, item_id, quantity, size)
VALUES (?,?,?,?,?)
ON DUPLICATE KEY UPDATE
size = VALUES(size)
");
} else {
// If user level is not 1,2, or 3, skip the operation
continue;
}
$orderStmt->bind_param("siiis", $branch, $userId, $id, $quantity, $sizesString);
$orderStmt->execute();
}
header("Location: order.php");
exit();
} else {
header("Location: order.php");
exit();
}
?>
Note: The 59 was manually inputted through mysql.\table[[Day,Meal Type,Type,Item,Size,Color,Site,Quantity],[Monday,Lunch,Fried,Fried German Franks,Small,Large,XL,Brown,On Site,59],[Monday,Breakfast,Fried,Hungarian Sausage,Small No Fry,Medium No Fry,Large,Brown,On Site,0],[Monday,Breakfast,Fried,Fried Luncheon Meat,Small,Brown,On Site,0]]
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions