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
https://forums.phpfreaks.com/topic/256388-association/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.