* Resolved *
I implemented SimpleCart(js) to my one project.
One can register and login.
Once logged in you can use the cart to purchase items.
I have one problem, because simplecart(js) saves the cart to localstorage, if you login with a other account. You see the same cart results.
Does anyone have a php sql solution for this, to store the cart results into sql for each individual session user?
I resolved this issue with this,
It’s a basic technique, but it works perfectly for what I need, I’ll still tweak the php to check if the cart item exists in the db, whether to update or create.
jQuery
$(".saveCart").click(function(){
$(".itemRow").each(function(){
var custId = "<?php echo $_SESSION['Username'] ?>";
var itemName = $(this).find(".item-name").text();
var itemPrice = $(this).find(".item-price").text();
var itemQty = $(this).find(".item-quantity").text();
var itemTotal = $(this).find(".item-total").text();
$.ajax({
// Enter below the full path to your "cart" php file
url: "cart.php",
type: "POST",
data: {custId: custId, itemName: itemName, itemPrice: itemPrice, itemQty: itemQty, itemTotal: itemTotal},
cache: false,
success: function (html) {
// If form submission is successful
if ( html == 1 ) {
}
// Double check if maths question is correct
else {
}
}
});
});
});
PHP
<?php
$con = mysql_connect("localhost","root","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$sql="INSERT INTO cart (Id, itemName, itemPrice, itemQty, itemTotal)
VALUES
('$_POST[custId]','$_POST[itemName]','$_POST[itemPrice]','$_POST[itemQty]','$_POST[itemTotal]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
if ($sql) { echo "1"; }
else {echo "2"; }
mysql_close($con);
?>
Something like that?