Twinkie
Banned
- Messages
- 1,389
- Reaction score
- 12
- Points
- 0
I hit a wall where I cannot figure out what is wrong with the block of code in this page. It is a simple shopping car script that when given the correct URI, it will add an item to the shopping cart.
The code on lines 8 and 9 are the problem, and its doing something weird to the arrays. Whats wrong with it or is there a better cod snippet I should be using? :dunno:
If you visit the page, for diagnostic purposes, the shopping cart is printed to the screen. Adding ?do=clear to the URL will unset the session data.
PHP:
session_start();
$query = "SELECT ID FROM Items WHERE ID = " . mysqli_real_escape_string($con,$_GET["id"]);
if ($_GET["do"] === "add" && @mysqli_query($con,$query)) {
if (isset($_SESSION["cart_id"])) {
if (array_search($_GET["id"],unserialize($_SESSION["cart_id"])) === false) {
$_SESSION["cart_id"] = serialize(array_push(unserialize($_SESSION["cart_id"]) , $_GET["id"] ));
$_SESSION["cart_qty"] = serialize(array_push(unserialize($_SESSION["cart_qty"]),1));
}
}
else {
$_SESSION["cart_id"] = serialize(array($_GET["id"]));
$_SESSION["cart_qty"] = serialize(array(1));
}
}
If you visit the page, for diagnostic purposes, the shopping cart is printed to the screen. Adding ?do=clear to the URL will unset the session data.