Jump to content

association


searls03

Recommended Posts

what I would like to do is have a query that if $product_id with specific $cart_id is already present in database, then it will update quantity instead of inserting a new row, but if $product_id is not present with specific $cart_id(important that it isn't with this) then it will insert a new row.  can anyone help?

<?php
include_once("connect.php");
session_start();

if($_POST['submit'])
{
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM cart where cart_id = ".$_SESSION['cart_id']."");
while($row = mysql_fetch_array($sql)){
$product = $row["product123"];
$price1 = $row["price"];
$id = $row["product_id"];
$qty = $row["quantity"];
}
$product = mysql_real_escape_string($_POST['hiddenField']);
$price = mysql_real_escape_string($_POST['hiddenField1']);
$id = mysql_real_escape_string($_POST['hiddenField2']);

$sql = "INSERT INTO cart (price, product123, quantity, cart_id, product_id) 





VALUES('$price', '$product', '1', '".$_SESSION['cart_id']."', '$id' )";
$rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error());
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.