/    Sign up×
Community /Pin to ProfileBookmark

Question about requests

Hello

I’m a newbie of PHP and must develope a very simple shop cart (no pay functionality etc)
On every page I have up to 20 products (its dynamic depending on what area the vistor visits).

I thought I could do something like this…
1) The visitor choose numbers of one product and hit the button ‘add to shop cart’
2) on the page add.php I make a readrequest (POST) what has been submitted.

Lets say I have 20 products on one page and the visitor choose to submit item nr 4…how do I solve that when reading the request in add.php as I know I have to know which items that belongs to the form on the previous page so I can make a read request of submitted item.

Is there a way to solve this dynamicly…or do you recommend me to do this request through GET request?

Thanks in advance

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarMay 03.2005 — each item should have it's own unique ID.

and if every item has a different ID you should be able to ignore where they came from(although it wouls be nice to hold it in a session for redirection purposes).
Copy linkTweet thisAlerts:
@digital_stormauthorMay 03.2005 — Hello

Yes all my items have their unique id but as I know from PHP I have to do like this to get a value from the request $_POST['name of my item']; that means that I have to controll all items under current category if they are set on previous page or not or am I missing something?

My thought was to save a 'shop cart' as a session object including objects of kind 'orderers'

Thanks for helping me

/D_S





each item should have it's own unique ID.

and if every item has a different ID you should be able to ignore where they came from(although it wouls be nice to hold it in a session for redirection purposes).[/QUOTE]
Copy linkTweet thisAlerts:
@scragarMay 03.2005 — <a href="buy.php?id=xx"><img src="buyNow.gif" alt="Buy Now"></a>


buy.php:[code=php]$ID = $_GET['id'];
if(preg_match("/[^0-9]/", $ID)){//error, not a number for ID
echo "we appear to have a problem, your item ID was invalid.";
}else{
if(mysql_num_rows(mysql_query("SELECT id FROM items WHERE id=$ID"))){
//item exist
echo "item added to your cart.";

// add the item to the cart and stuff.

}else{
echo "item cannot be found, please try again.";
};
};[/code]
Copy linkTweet thisAlerts:
@digital_stormauthorMay 03.2005 — Thank you very much!

/D_S


<a href="buy.php?id=xx"><img src="buyNow.gif" alt="Buy Now"></a>


buy.php:[code=php]$ID = $_GET['id'];
if(preg_match("/[^0-9]/", $ID)){//error, not a number for ID
echo "we appear to have a problem, your item ID was invalid.";
}else{
if(mysql_num_rows(mysql_query("SELECT id FROM items WHERE id=$ID"))){
//item exist
echo "item added to your cart.";

// add the item to the cart and stuff.

}else{
echo "item cannot be found, please try again.";
};
};[/code]
[/QUOTE]
×

Success!

Help @digital_storm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...