darkfreaks Posted July 5, 2008 Share Posted July 5, 2008 Code 1: <?php /*If user has logged in, test to see whether cart has been submitted. If so, save items to $_SESSION array and load cart.php */ elseif (isset($_POST['tocart'])|| $_POST['tocart'] == "yes"||!empty($_POST['tocart'])) { if (isset($_POST['buyid'])|| $_POST['buyid'] == "selected"||!empty( $_POST['buyid']) ) { $_SESSION['Cartitems'] = array($_POST['buyid']); } header("location: cart.php"); exit(); } /*If user has logged in and has not yet submitted the page, load this*/ else { /*Test to see whether category dropdown was selected*/ if(isset($_POST['cat_select']) || $_POST['cat_select'] == "yes"|| !empty( $_POST['cat_select'])) { include("cat_select.inc"); /*Check the Database for all items within that category*/ $sql = "SELECT * FROM $tablename WHERE Category='$_POST[Category]'"; $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query."); /*FORM TO PLACE ORDER*/ include("order_form.inc"); exit(); } ?> Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582483 Share on other sites More sharing options...
darkfreaks Posted July 5, 2008 Share Posted July 5, 2008 it makes sure the post variable isnt empty also Code: if ($ItemID == @$_POST['buyid']){ should be: if ($ItemID = $_POST['buyid']){ Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582484 Share on other sites More sharing options...
Becca Posted July 5, 2008 Author Share Posted July 5, 2008 should be: if ($ItemID = $_POST['buyid']){ Problems with that is that when I remove that I get the following error: Notice: Undefined index: buyid in C:\xampp\htdocs\dynamicphp\supportfiles\order_form.inc on line 22 My guess is that it's because until you actually hit the "Add to Cart" Button, $_POST['buyid'] doesn't exist? ??? Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582535 Share on other sites More sharing options...
darkfreaks Posted July 5, 2008 Share Posted July 5, 2008 you need to put your post variables inside variables. <?php $buyid= $_POST['buyid']; if($ItemID!=$buyid) { //error }else{ //code }?> logic girl LOGIC!!! Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582539 Share on other sites More sharing options...
Becca Posted July 5, 2008 Author Share Posted July 5, 2008 That bit of code doesn't make much sense to me. It seems as though it just makes the script more complicated to assign a variable to a variable rather than to suppress a message the first time the page runs? Tried the code out, though, but when I then change it, I get a similar message staying that 'buyid' is an undefined variable. Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582572 Share on other sites More sharing options...
darkfreaks Posted July 5, 2008 Share Posted July 5, 2008 what is buy id? if there variable is undefined its abit pointless, you will keep getting that error until you define it. Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582573 Share on other sites More sharing options...
Becca Posted July 6, 2008 Author Share Posted July 6, 2008 I went through and did something that makes more sense, changing the name of the radio buttons from 'buyid' to '$Category', so that they'll be named according to type of furniture (tables, chairs, etc). However, it seems that once again, it's not passing the variable in the $_SESSION array (although it did when I first changed it... ???) I appreciate your patience and all the help you've provided thus far Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582583 Share on other sites More sharing options...
darkfreaks Posted July 6, 2008 Share Posted July 6, 2008 if buyid is an add ot cart button wouldnt it be easier to have a mysqli field named buyid and have it INT 1? then if int 1 its added to cart and if int zero it isnt ??? Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582585 Share on other sites More sharing options...
Becca Posted July 6, 2008 Author Share Posted July 6, 2008 Um...huh? Sorry, not quite sure what you're saying - I think you're asking about why I'm not placing it in a mysql database? My teacher told me that we weren't going as deep as building a secondary database for orders, that the information can be passed within the $_SESSION array, so that is how I am trying to do it. :-\ Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582594 Share on other sites More sharing options...
darkfreaks Posted July 6, 2008 Share Posted July 6, 2008 also you sure its buyid? it could be something else on the form. might wanna refer to your form input and make sure its spelled right. or else it will throw an undefined error Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582597 Share on other sites More sharing options...
Becca Posted July 6, 2008 Author Share Posted July 6, 2008 Hmmm, for some reason, trying to make the name of the radio button dynamically change with $Category doesn't work. It'll pass the value in the view source code to the form, but it won't pass the item via $_POST['$Category'] to create the array. But, when I change the name to 'buyid' again, it passes it to the array just fine. ??? Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582606 Share on other sites More sharing options...
darkfreaks Posted July 6, 2008 Share Posted July 6, 2008 ini_set('error_reporting',E_ALL); turns on error reporting Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582609 Share on other sites More sharing options...
Becca Posted July 6, 2008 Author Share Posted July 6, 2008 My error reporting is turned on already. I make sure to copy my headers from my prior work (basically the error setting and the location of the supportfiles) with each new assignment so that I don't forget. Thanks for all the help. Since I technically have the initial issue solved (the item is now passing in an array), I'm going to mark this as resolved. I'll definitely come back with more questions if any more arise. Everyone who responded was extremely helpful, and hopefully there'll come a time that I can return the favor for someone else. Thank you! Link to comment https://forums.phpfreaks.com/topic/113250-solved-basic-shopping-cart-trying-to-pass-information-via-_get-or-_session/page/2/#findComment-582623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.