Jump to content

[SOLVED] Basic Shopping Cart - trying to pass information via $_GET or $_SESSION


Becca

Recommended Posts

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

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? ???

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. :-[

 

 

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 :)

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.  :-\

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.  ???

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.