lobfredd Posted April 20, 2012 Share Posted April 20, 2012 Hello. I am trying to make a very simple shopping cart. The add to cart button on a product simply just insert a record to my shopping cart table in MySQL. and then my shopping cart just reads from that table, and displays in a table. What i want now is a "remove from shopping cart" button, a button that removes the product on the same line as the button. How do i do that? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/261307-making-a-shopping-cart-delete-from-specific-row/ Share on other sites More sharing options...
lobfredd Posted April 20, 2012 Author Share Posted April 20, 2012 Trying to explain a litte more I want this code to delete a record, but the table content is dynamic and changes everytime. DELETE FROM Persons WHERE bruker='{$_SESSION['MM_Username']}' AND vare='(WHATEVER IN the MONTH FIELD)' As you can see from this table i want the button to delete the record the button is in. (the table content is dynamic and changes everytime) I appreciate all the help i can get! Quote Link to comment https://forums.phpfreaks.com/topic/261307-making-a-shopping-cart-delete-from-specific-row/#findComment-1339084 Share on other sites More sharing options...
Drummin Posted April 20, 2012 Share Posted April 20, 2012 Your easiest option would be to put the form within the table cell. You probably have something like this in your loop. echo '<tr> <td>' .$month. '</td> <td>' .$saving. '</td> <td><form method="post" action=""><input type="submit" name="' .$month. '" value="Remove" /></form></td> </tr>'; Then for processing, (which should be at the top of the page) you can go. $deletemonth=array_keys($_POST); $sql="DELETE FROM Persons WHERE bruker='{$_SESSION['MM_Username']}' AND vare='{$deletemonth[0]}'"; Quote Link to comment https://forums.phpfreaks.com/topic/261307-making-a-shopping-cart-delete-from-specific-row/#findComment-1339135 Share on other sites More sharing options...
lobfredd Posted April 20, 2012 Author Share Posted April 20, 2012 Just got another problem here mysql_query("INSERT handlevogn SET vare='Kenny & the Superheroes', pris='199' bruker='{$_SESSION['MM_Username']}'") or die(mysql_error()); this code gives me the error massage: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'bruker=nruk' at line 1 As you can see it have got the username from the session. the query works fine without the line: bruker='{$_SESSION['MM_Username']}' so what is wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/261307-making-a-shopping-cart-delete-from-specific-row/#findComment-1339178 Share on other sites More sharing options...
Drummin Posted April 20, 2012 Share Posted April 20, 2012 Give this a go. $vare=mysql_real_escape_string('Kenny & the Superheroes'); $pris=mysql_real_escape_string('199'); $bruker=mysql_real_escape_string($_SESSION['MM_Username']); $sql="INSERT INTO handlevogn (vare,pris,bruker) VALUES ('$vare','$pris','$bruker')"; mysql_query($sql) or trigger_error($sql . ' has encountered and error<br />' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/261307-making-a-shopping-cart-delete-from-specific-row/#findComment-1339179 Share on other sites More sharing options...
lobfredd Posted April 20, 2012 Author Share Posted April 20, 2012 Thanks! Now i am wandering how to make the same random ordernumber to all the records that gets submitted at the same time. mysql_query("INSERT INTO ordre (vare, pris, bruker) SELECT vare,pris,bruker FROM handlevogn WHERE handlevogn.bruker='{$_SESSION['MM_Username']}'")or die(mysql_error()); as you can see if there is multiple records in the handlevogn table many records will be inserted in the ordre table. possible to make em all get the same order number? Quote Link to comment https://forums.phpfreaks.com/topic/261307-making-a-shopping-cart-delete-from-specific-row/#findComment-1339204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.