Jump to content

Becca

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Becca's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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!
  2. 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. ???
  3. 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. :-\
  4. 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
  5. 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.
  6. Problems with that is that when I remove that I get the following error: My guess is that it's because until you actually hit the "Add to Cart" Button, $_POST['buyid'] doesn't exist? ???
  7. Removing the @ from the line if ($ItemID == @$_POST['buyid']) generates this error: Undefined index: buyid in C:\xampp\htdocs\dynamicphp\supportfiles\order_form.inc on line 22 From my class, it was my understanding that you use the @ in the $_POST['var'] Variable in the initial code to suppress the error because you will always get an error the first time the code runs, since the variable doesn't exist until you post - is that incorrect? Can you clarify what this bit of code states? if (isset($_POST['buyid']) || $_POST['buyid'] == "selected"||!empty($_POST['buyid'])) Particularly confused by the || marks and what the !empty($_POST['buyid']) Signify And, out of curiosity, is there a reason that && is preferred to and, since they both do the same thing? My class never discussed &&.
  8. Once again, my code broke in furniture.php and is not passing the array. ??? As soon as I get that fixed, I'll definitely try using count vs. sizeof and see whether that makes any difference... Not sure why, because I stopped editing it when it started working again. I've posted the portion of the code below that I suspect must contain my error... <?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']) and $_POST['tocart'] == "yes") { if (isset($_POST['buyid']) and $_POST['buyid'] == "selected") { $_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']) and $_POST['cat_select'] == "yes") { 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(); } And for reference, order_form.inc, which I simply extracted from furniture.php to help clean up the code in hopes of determining the error there: <html> <head> </head> <body> <?php echo "<form action='$_SERVER[php_SELF]' method='POST'>"; echo "<table border='1' cellpadding='5'><tr>"; /*Run a while loop that displays each item found by the inquiry*/ while($row = mysqli_fetch_assoc($result)) { extract($row); echo "<td><img src='$ImgURL'><br />"; echo "$ItemName <br />"; echo "$ItemDesc <br />"; echo "$ $Price <br /><input type='radio' name='buyid' value='$ItemID'"; /*If the item is selected, indicate this when information is sent*/ if ($ItemID == @$_POST['buyid']) { echo "selected='selected'>\n"; } else { echo ">\n"; } echo "Buy Me!</td>"; } echo "</tr></table>"; echo "<div id='submit'><input type='hidden' name='tocart' value='yes'><input type='submit' value='Add to Cart'></div></form>"; ?> </body> </html>
  9. Oh! So that's what @ does (where's the lightbulb over the head emoticon when you need one?) I've once again gotten the selection to pass through the array again (although I'm not sure HOW, since all I did was clean up my furniture.php file by moving the form portion that displays the products and allows you to select them to an include file...). Now my issue is testing the sizeof $items, which is still remaining at 0. I removed the @, but am not receiving any errors, so it would still appear to be the case that the array is not what's being tested by the if(sizeof($items = 0) Hmmm.... You guys are awesome, and thanks for the clarifications you've all given so far!
  10. Hmmm...scratch that, the changes no longer seem to be passing items to the array - array = NULL... ???
  11. I'm using an array because that's how my teacher advised me that that would be how best to pass them via $_SESSION, because the lesson is about learning to pass things through $_SESSION or as a cookie (and I understood the cookies section fairly well, so thought it best to tackle and learn what I understood the least to learn it). This is the same reason that I'm not using a database (I had initially planned to do a database for the orders, using an order id to track what the person placed in the cart (and to track the session), but for what this assignment is supposed to be, that's not necessary. I was initially trying to pass things via the URL, but couldn't figure out how to grab them from the URL and then pass them into the page on cart.php. I'm using an array to track the items in their shopping cart and displaying them in a table on cart.php. I tried using ob_start and ob_end_flush at the beginning and end of the script, but this produces the same issue, leading me to believe that I'm somehow testing for the wrong thing... In changing my elseif to this in furniture.php: elseif (isset($_POST['tocart']) and $_POST['tocart'] == "yes") { if (isset($_POST['buyid']) and $_POST['buyid'] == "selected") { $_SESSION['Cartitems'] = array($ItemID); } header("location: cart.php"); exit(); } This should be passing things to the $_SESSION['Cartitems'] array, and it finally seems to be doing so (verified by adding var_dump($_SESSION); to the top of my cart.php script). I then assigned the array to a variable $items and ran a check to see if $items == 0 (that there are no items in the shopping cart) $items = array($_SESSION['Cartitems']); /*If there are no items in the cart, provide a link to go back to the catalog*/ if(@sizeof($items == 0)) { echo "There are no items currently in your cart<br /><a href='furniture.php'>Click here to continue shopping</a>"; } My script seems to be halting here, and running this portion of the script, even when var_dump is telling me that the 'Cartitems' array has an item in it. I figure that this means that the variable being tested in the size of line is NOT the 'Cartitems' array, but I can't seem to figure out how I might word it to test for the appropriate thing, if this is incorrect... ???
  12. Hmmm...the other PHP pages I've written using and vs && have worked. But, tried the syntax that you provided, and it still seems to be doing the same thing (running as though there are no variables saved to the session that is). ??? This is probably the most challenging stuff I've learned in web coding so far (and, also the most interesting - probably because it's challenging ) - I just hope to get the hang of things soon enough! I appreciate all the help!
  13. Thanks, that got rid of the error message for the unidentified variable. So with eliminating the array, I now have this code: foreach($_SESSION['Cartitems'] as $key => $value) { $sql = "SELECT * FROM $tablename WHERE ItemID='$_SESSION[itemID]'"; $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query."); echo "<tr><td>$ItemID</td></tr>"; } But the variable doesn't seem to be carrying over - instead, it's outputting this command: if(@sizeof($_SESSION['Cartitems'] = 0)) { echo "There are no items currently in your cart<br /><a href='furniture.php'>Click here to continue shopping</a>"; } Rather than going on to try to echo the items. Is the code below not doing what I'm expecting it to do - which is saving $ItemID in the $_SESSION if the radio item is selected on post? elseif (isset($_POST['tocart']) and $_POST['tocart'] == "yes") { if (isset($_POST['buyid']) and $_POST['buyid'] == "selected") { $_SESSION['Cartitems'] = "$ItemID"; } header("location: cart.php"); exit(); }
  14. If I don't need the array, how would I walk it through the foreach loop? (sorry I'm REALLY new to PHP). Outside of that, even removing that, the error will just move from the line where I'm assigning the array as $items, to where I'm running through the foreach loop, where I'm trying to use $_SESSION['var']. ???
×
×
  • 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.