Jump to content

Making a shopping cart. Delete from specific Row


lobfredd

Recommended Posts

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

Link to comment
Share on other sites

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)

table.png

 

I appreciate all the help i can get!

Link to comment
Share on other sites

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]}'";

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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?

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.