Jump to content

lollipop2468

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lollipop2468's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks requinix! Something so simple! I'm trying to learn the basics and struggling to find a guide that explains it easily! So will ' ?' check for either space or no space? If a line was approved as either having/not having a space, is it then possible to strip out the space if you were then going to insert that line into a database?
  2. lollipop2468

    Space?

    Apologies for the ridiculousness of this question! I am a newbie so please be patient! I am trying to match groups of numbers and letters, however how do I match a possible space in an expression? By this I mean if a user entered 'ABCD 1234' how can I get it to match with ABCD1234? This is most likely a very simple piece of code - ive searched all afternoon and can not find anything to explain how it is done! Thanks
  3. Thanks for all your help CPD!!! SOLVED IT!!!! What is was doing was using 'pid' throughout when it should have been '$item'. So much stress over something so small..... Now just to output a price and work out shipping!!! Thanks!!!
  4. Thanks CPD - turn out in the array I was mentioning item_id and item. Corrected that now and its updating fine! On the cart page I use: if (isset($_POST['pid'])){ $item = $_POST['pid']; $wasFound = false; $i = 0; Which accepts the 'pid' from the add to cart button on the product page here: <form id="form1" name="form1" method="POST" action="cart.php"> <input type="hidden" name="pid" id="pid" value="blueplate" /> <input type="submit" name="button" id="button" value="Add to Shopping Cart" /> </form> Should I be doing anything else or should this work and ive just gone wrong somewhere!
  5. Thank you for your help - I really appriciate it!! Ive have included the changes you suggested (Drummin) - however the item still isn't being passed which I think is causing nothing to show. Something is going through as this is in the array print out: Array ( [0] => Array ( [item] => [quantity] => 1 ) [1] => Array ( [item_id] => [quantity] => 3 ) ) It seems as if its not passing the 'redplate' from the product page into the cart page for it to query it and get its details out? CPD - Thank you so much for taking the time to help me out too! Im a newbie to this so trying to take little steps - just ending up in a muddle!
  6. Thanks for your reply! Ive updated the code with what you suggested...however it seems as if nothing is still being passed and it is showing duplicate entries (The entries are appearing but with empty data)?
  7. For some reason my session variable isn't been populated with my items as they are being passed? Can anyone point me in the direction why? It will add an item into the array, however it will only display one at a time on the cart page. Meaning if I add one item A and then add an item B, item B will only be shown on the cart page. This is just a test i'm playing with to help understand php a little more - obviously I need more practice! Product Page <?php $result = mysql_query ('SELECT * FROM stock WHERE item="redplate"'); // fetch the resulting row as an associative array while ($row = mysql_fetch_assoc ($result)){ echo '£', number_format( $row ['price'] / 100, 2, '.', ' ' ); } ?> <form id="form1" name="form1" method="post" action="cart.php"> <input type="hidden" name="item" id="item" value="redplate" /> <input type="submit" name="button" id="button" value="Add to Shopping Cart" /> Shopping Cart Page <?php session_start(); ?> <?php include 'dbconfig.php'//connects to database?> <?php include 'connect.php'//checks my credentials?> <?php ////Adding something to the shopping basket from product page if (isset($_POST['item'])){ $item = $_POST['item']; $wasFound = false; $i = 0; //If cart is not set or cart array empty if (!isset($_SESSION['cart_array'])||count($_SESSION['cart_array']) < 1) { //Run if the cart is empty or not set $_SESSION['cart_array'] = array(1 => array('item' => $item, 'quantity' => 1)); }else{ //Run if the cart has at least one item foreach ($_SESSION['cart_array'] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == 'item' && $value == $item) { //This item is already in our shopping cart so add one to quantity array_splice($_SESSION['cart_array'], $i-1, 1, array(array('item' => $item, 'quantity' => $each_item['quantity']+1))); $wasFound = true; } //Close if condition } //Close While loop }//Close foreach loop // if ($wasFound == false) { array_push($_SESSION['cart_array'],array('item' => $item, 'quantity' => 1)); } } } ?> <?php //////If a user empties their cart if (isset($_GET['cmd'])&& $_GET['cmd']=="emptycart") { unset($_SESSION["cart_array"]); } /////This will empty their cart and reset array ?> <?php ///// Puts cart together for shopper to view $cartOutput=""; if (!isset($_SESSION['cart_array'])|| count($_SESSION['cart_array'])<1){ $cartOutput = "<h2 align='center'>Your shopping basket is empty</h2>"; } else { $i = 0; foreach ($_SESSION['cart_array'] as $each_item){ $i++; $item_name = $each_item['item']; $sql = "SELECT * from stock WHERE item = '$item'"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ $product_name=$row['name']; $price=$row['price']; } $cartOutput = "<h2>Your Shopping Basket $i</h2>"; $cartOutput = "Item Name: " .$each_item['item']. "<br />"; $cartOutput = "Item Quantity: ". $each_item['quantity']. "<br />"; //while (list($item, $price) = each($each_item)){ //$cartOutput = "$key: $value<br />"; // } } } ?> //If user chooses to empty their shopping cart) <?php if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") { unset($_SESSION["cart_array"]); } ?> <a href="cartaction.php?cmd=emptycart">Click Here to Empty Your Shopping Cart</a>
×
×
  • 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.