Jump to content

Recommended Posts

Basically im newish to php and im having a go at making a cart, and i have already made the infastructure of the other tables. The cart tutorials are really unclear to me so does anybody know a decent tuorial or explanation to this line of code...

<a href="cart.php?action=add_item&id=<?php echo $row["itemId"]; ?>&qty=1">Add Item</a>

 

Thanks ???

Looks like when someones clicks on that link it sends them to the processing page (cart.php) where it's going to add the item that they selected ($_GET['id']) with the quantity of 1 ($_GET['qty']).

 

It's utilizing the GET method.

 

The link is generated dynamically, and the value for the URL parameter 'id' is generated from the results of the query to the database.

the question marks seperates the file from the variables being set via the url...cart.php is the same as cart.php?

 

the variables are set via $_GET['variable']....so the 'action' variable is set to Add_item...the &'s seperate each variable and what they're set to...the file(cart.php) pulls those variables out of the url and uses them in the script.

The skeleton of your script probably looks something like this.  So first let me explain how it's being generated.

 

$sql = "SELECT * FROM items";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
?>
&qty=1">Add Item
}
?>

 

Your script queries the database and grabs all of the unique ID's for the items and assigns 'id' to it.  The '?' and '&' characters are how you append these values to the URL.  '?' is used for the very first one, and any additional values you must use the '&' symbol.

 

If you go to the cart.php page, and look for 'add_item', which is the action you're taking when you get there, then you will see $_GET['id'] and $_GET['qty'] which will be used to add that item to the customers cart (session or DB) with the quantity of 1.

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.