searls03 Posted February 4, 2012 Share Posted February 4, 2012 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 More sharing options...
Pikachu2000 Posted February 4, 2012 Share Posted February 4, 2012 INSERT . . . ON DUPLICATE KEY UPDATE Link to comment https://forums.phpfreaks.com/topic/256388-association/#findComment-1314416 Share on other sites More sharing options...
searls03 Posted February 4, 2012 Author Share Posted February 4, 2012 but the problem I have is associating the two with each other.....that is the main thing I need......... Link to comment https://forums.phpfreaks.com/topic/256388-association/#findComment-1314418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.