Jump to content

Alexhoward

Members
  • Posts

    310
  • Joined

  • Last visited

    Never

Everything posted by Alexhoward

  1. Sorted! foreach ($_SESSION['cart'] as $product_id => $quantity) { Thanks for all your help!
  2. Thanks for the reply, i've given this a go, but all i can get back is the quantity of the products...? the products are stored in the session as: $_SESSION['cart'][$product_id] so the count is stored in the session, and the product id in the second part... could someone please help me out? Thanks!
  3. Sorted It was because i was doing the real_escape thing before connecting to the database and it didn't like that... so moved it and it works now thanks for all your help guys!
  4. Hi, As i've just realised, it all works fine with the real_escape commented out however, i obviously want to protect against sql injection and the like but when i turn it on it doesn't work anymore.... any ideas...? thanks for all this
  5. OK, it's just stuck in a load of other code, so i'll just pull out the bits that are relevant : input page <form method='post' action='adamount.php'> <td> Please enter the required amount * : £ <input type='text' name='amount' value='0.00' style='width: 60px'> $error </td> <tr> <td align='right'> <input type='submit' name='go' value='Submit' /> </td> </tr> </form> and the adamount.php page : <?php //$_POST['amount'] = mysql_real_escape_string($_POST['amount']); //check amount over £5 has been entered if($_POST['amount'] < 5 ) { header( 'Location: http://www.mysite.co.uk/folder1/folder2/inputpage.php?error=1' ) ; exit; } else { some code here ?>
  6. No Wait! it wasn't that...!! i'd commented out the real_escape_string! so how can i protect myself if i can't use real escape....?!?
  7. Hi Guys, Think I've sorted it... I was running a redirect if the amount was less than 5 to bring up an error message, don't think i had it quite right in the IF statment, so whatever the out come it would always redirect with the error. sorry to waste your time, you know how it gets starting at code for too long Thankyou all for your input! apologies again
  8. Hi Guys, Thanks for the feedback the code above above is just an example... i've echoed the post an it's coming back fine, as in whatever you type in.. the floatval made no difference... but thanks that's something i didn't know i've tried it without the value='0.00' ... no difference is it something to do with the way i'm saying : if($_POST['amount'] < 5 )
  9. Hi Guys, sure i'm doing something stupid here. so, i've got a form : for example : <form method='post' action='page2'> <input type='text' name='amount' value='0.00' style='width: 60px'> </form> the user enters an amount then i pick it up : <?php if($_POST['amount'] < 5 ) { this } else { this } ?> but it doesn't seem to matter what amount i put in it always thinks it less than 5...? could anyone help me? Thanks in advance!
  10. Hi, thanks again, i've got all our stock info in mysql already, and will be using paypal as the payment route. therefore when i get the success message from paypal (payment confirmed), i will complete the order and subtract the stock quantity . my only issue is trying to work out how to get the order out of the session and into the database...? just can't visualise how it works...? do you know of a good tutorial here or anywhere else that can help me? or even what that kind of process would be called...? I truely have no idea... cheers
  11. Hi xtopolis, Thanks for having the patience with this it's a bit hard to explain... i think they are in an array see: http://www.phpfreaks.com/forums/index.php/topic,218849.msg1002551.html#msg1002551 they are all stored in one session , with multiple products, so : $_SESSION['cart'][$product_id] this will be once items have been purchased, so i can subtract them from our stock, as well as save them so customers can view their orders and track progress
  12. How do you mean...? Do some kind of loop and save them into SQL...?
  13. Good Evening, I'm not even sure where to start with this! i've got a shopping basket that stores all the products in different sessions, i'd like to be able to save these somehow, so customers can pull them up again in their historical/order tracking page... i honestly don't even know where to start! would someone be able to point me in the right direction..? Thanks in advance!
  14. Excellent! Thankyou so much, it's working! error free! i've used the code below to show the basket empty message, and all's cool! if (!isset($_SESSION['a'][$product_id])&&@$_SESSION['a'][$product_id] == 0) { Thanks again!!
  15. Hi, Apologies, i meant to write the error! It's when you press "Empty Basket" Undefined index: in E:\********************\basket.php on line 60 What i'd like to happen is either when you reduce the quantity to zero, and it unsets the session, (so nothing is in the basket) you get "your basket is empty", or when you press "Empty basket" i only get this error at the moment when you press empty basket, not by reducing the quantity Thanks again for your help p.s. this is using the code above (your new one)
  16. Thanks for all this. i've learnt alot but i'm obviously still a noob!! i've been messing about a bit, and have commented out the section that says "your basket is empty" but here it is in it's current state. thanks again! <?php session_start(); ?> <style type="text/css"> <!-- .style1 {font-size: 24px} .style2 {font-size: 12px} .style4 {font-size: 12px; font-weight: bold; } --> </style> <p><a href="http://www.everyonlinestore.co.uk/snookereast/index.php"><img src="images/logo.jpg" alt="Snooker East" border="0" longdesc="http://www.everyonlinestore.co.uk/snookereast/index.php" /></a></p> <p class="style1">Your Shopping Basket </p> <p class="style1"><span class='style4'><a href="basket.php?action=empty">Empty Basket</a></span></p> <table width='800' border='1' cellspacing='0' cellpadding='0'> <tr> <td align='left' bgcolor='#C9E4E4'><span class='style4'>Product</span></td> <td align='center' bgcolor='#C9E4E4'><span class='style4'>Quantity</span></td> <td align='center' bgcolor='#C9E4E4'><span class='style4'>Amount</span></td> </tr> <?php include("config.php"); //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die ("Could not connect to mysql because ".mysql_error()); //select the database mysql_select_db($db) or die ("Could not select database because ".mysql_error()); if(!isset($_GET['id'])) { $_GET['id'] = " "; } $product_id = $_GET['id']; if(!isset($_GET['action'])) { $_GET['action'] = " "; } $action = $_GET['action']; function productExists($product_id) { $sql = sprintf("SELECT id FROM products "); return mysql_num_rows(mysql_query($sql)) > 0; } if($product_id && !productExists($product_id)) { die("Error. Product Doesn't Exist"); } if (!isset($_SESSION['a'])) { $_SESSION['a'] = array(); } if (($action=="add"||$action=="remove"||$action=="empty")&&!isset($_SESSION['a'][$product_id])) { $_SESSION['a'][$product_id] = 0; } if($action == "add" ) { $_SESSION['a'][$product_id]++; } else if ($action == "remove" ) { $_SESSION['a'][$product_id]--; } else if($action = "empty" ) { $_SESSION['a'] = array(); } if($_SESSION['a'][$product_id] == 0 ) { unset($_SESSION['a'][$product_id]); } foreach($_SESSION['a'] as $product_id => $quantity) { $sql = sprintf("SELECT name, description, price, pandp FROM products WHERE id = %d;", $product_id); $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { list($name, $description, $price, $pandp) = mysql_fetch_row($result); $line_cost = $price * $quantity; if(!isset($total)) { $total = 0; } $total = $line_cost + $total; if(!isset($post)) { $post = 0; } $post = $pandp; print " <tr> <td width='66%'><span class='style2'>$name</span></td> <td width='15%' align='center' valign='middle'><span class='style2'><a href='basket.php?action=remove&id=$product_id'><img src='images/minus.jpg' alt='Remove' width='15' height='15' border='0' valign='middle' /></a> <input type='text' value='$quantity' style='width:30' /> <a href='basket.php?action=add&id=$product_id'><img src='images/plus.jpg' alt='Add' width='15' height='15' border='0' valign='middle' /></a></span></td> <td width='17%' align='right'><span class='style2'>£ $line_cost</span></td> </tr>"; } } //if(($action=="empty")&&!isset($_SESSION['a'][$product_id])) { //$total = 0.00; // print " // <tr> // <td width='66%'><span class='style2'>Your Basket is Empty...</span></td> // <td width='15%' align='center' valign='middle'><span class='style2'>0</span></td> // <td width='17%' align='right'><span class='style2'>0.00</span></td> // </tr>"; // } ?> <tr> <td colspan='3' align='right' bgcolor='#E6E6E6'><span class='style2'>Shipping & Handling Included</span></td> </tr> <tr> <td colspan='3' align='right' bgcolor='#E6E6E6'><span class='style2'><strong>Total : £ <? echo $total ?></strong></span></td> </tr> </table> <a href="index.php">Continue Shopping</a>
  17. Hi Mate, cheers for all your help, that's great, and with each question i ask i am learning more and more, however... when the basket is empty, or i press empty basket i am still getting errors... i take it if it's unset, then it's set to zero, however if i try to display "your basket its empty when it's zero i still get an error...
  18. Cheers F1 Fan, But i can't seem to get it to get rid of the error....?
  19. excellent!! isn't it obvious when you see it! that's sorted out error 1 - intial adding to the basket! error 3 is probably a similar affair then. when you empty the basket you get the error : Undefined index: a presumably because it doesn't exsist anymore... cheers
  20. hi, thanks for replying, the session_start's fine, although i've changed it for good measure. I did see it, but because it was ok i left it. doesn't make any difference on change thou... My thought's where the same, because it's trying to add to an exsisting, if it's already set. but i don't know how to fix it... any ideas? cheers
  21. Good Evening, Please see below links for a live example in test enviroment, with test data, thanks : http://www.everyonlinestore.co.uk/snookereast/index.php http://www.everyonlinestore.co.uk/snookereast/basket.php i'm having real problems trying to get the errors to go away with this.. errors i have : 1) initial add to basket creates an error with the session, press the plus to add another and it goes away... 2) Reduce the number in basket to zero, and the session is unset, and removed from the basket, but the "your basket is empty" message doesn't appear, erroring my total line... 3) Empty the basket link, on the basket page, displays the "your basket is empty" message, but displays an error... I've been fiddling with this all night but getting nowhere, would someone be able to offer me any advice, or point me in the right direction? Thanks for all the help this forum offers! Alex Howard. p.s. Here's the full code i am using. produts are added via - basket.php?action=add&id=$product_id Products are removed via - basket.php?action=remove&id=$product_id basket is emptied via - basket.php?action=empty <? session_start() ?> <style type="text/css"> <!-- .style1 {font-size: 24px} .style2 {font-size: 12px} .style4 {font-size: 12px; font-weight: bold; } --> </style> <p><a href="http://www.everyonlinestore.co.uk/snookereast/index.php"><img src="images/logo.jpg" alt="Snooker East" border="0" longdesc="http://www.everyonlinestore.co.uk/snookereast/index.php" /></a></p> <p class="style1">Your Shopping Basket </p> <p class="style1"><span class='style4'><a href="basket.php?action=empty">Empty Basket</a></span></p> <table width='800' border='1' cellspacing='0' cellpadding='0'> <tr> <td align='left' bgcolor='#C9E4E4'><span class='style4'>Product</span></td> <td align='center' bgcolor='#C9E4E4'><span class='style4'>Quantity</span></td> <td align='center' bgcolor='#C9E4E4'><span class='style4'>Amount</span></td> </tr> <?php include("config.php"); //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die ("Could not connect to mysql because ".mysql_error()); //select the database mysql_select_db($db) or die ("Could not select database because ".mysql_error()); if(!isset($_GET['id'])) { $_GET['id'] = " "; } $product_id = $_GET['id']; if(!isset($_GET['action'])) { $_GET['action'] = " "; } $action = $_GET['action']; function productExists($product_id) { $sql = sprintf("SELECT id FROM products "); return mysql_num_rows(mysql_query($sql)) > 0; } if($product_id && !productExists($product_id)) { die("Error. Product Doesn't Exist"); } if($action == "add" ) { $_SESSION['a'][$product_id]++; } else if ($action == "remove" ) { $_SESSION['a'][$product_id]--; } else if($action = "empty" ) { unset($_SESSION['a']); } if($_SESSION['a'][$product_id] == 0 ) { unset($_SESSION['a'][$product_id]); } if(isset($_SESSION['a'])) { foreach($_SESSION['a'] as $product_id => $quantity) { $sql = sprintf("SELECT name, description, price, pandp FROM products WHERE id = %d;", $product_id); $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { list($name, $description, $price, $pandp) = mysql_fetch_row($result); $line_cost = $price * $quantity; if(!isset($total)) { $total = 0; } $total = $line_cost + $total; if(!isset($post)) { $post = 0; } $post = $pandp; print " <tr> <td width='66%'><span class='style2'>$name</span></td> <td width='15%' align='center' valign='middle'><span class='style2'><a href='basket.php?action=remove&id=$product_id'><img src='images/minus.jpg' alt='Remove' width='15' height='15' border='0' valign='middle' /></a> <input type='text' value='$quantity' style='width:30' /> <a href='basket.php?action=add&id=$product_id'><img src='images/plus.jpg' alt='Add' width='15' height='15' border='0' valign='middle' /></a></span></td> <td width='17%' align='right'><span class='style2'>£ $line_cost</span></td> </tr>"; } } } else { $total = 0.00; print " <tr> <td width='66%'><span class='style2'>Your Basket is Empty...</span></td> <td width='15%' align='center' valign='middle'><span class='style2'>0</span></td> <td width='17%' align='right'><span class='style2'>0.00</span></td> </tr>"; } ?> <tr> <td colspan='3' align='right' bgcolor='#E6E6E6'><span class='style2'>Shipping & Handling Included</span></td> </tr> <tr> <td colspan='3' align='right' bgcolor='#E6E6E6'><span class='style2'><strong>Total : £ <? echo $total ?></strong></span></td> </tr> </table> <a href="index.php">Continue Shopping</a> Thanks again
  22. OK, So i've ironed out what i had before it all went wrong... the code now looks like this: <? session_start() ?> <style type="text/css"> <!-- .style1 {font-size: 24px} .style2 {font-size: 12px} .style4 {font-size: 12px; font-weight: bold; } --> </style> <p><a href="http://www.everyonlinestore.co.uk/snookereast/index.php"><img src="images/logo.jpg" alt="Snooker East" border="0" longdesc="http://www.everyonlinestore.co.uk/snookereast/index.php" /></a></p> <p class="style1">Your Shopping Basket </p> <table width='800' border='1' cellspacing='0' cellpadding='0'> <tr> <td align='left' bgcolor='#C9E4E4'><span class='style4'>Product</span></td> <td align='center' bgcolor='#C9E4E4'><span class='style4'>Quantity</span></td> <td align='center' bgcolor='#C9E4E4'><span class='style4'>Amount</span></td> </tr> <?php include("config.php"); //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die ("Could not connect to mysql because ".mysql_error()); //select the database mysql_select_db($db) or die ("Could not select database because ".mysql_error()); if(!isset($_GET['id'])) { $_GET['id'] = " "; } $product_id = $_GET['id']; if(!isset($_GET['action'])) { $_GET['action'] = " "; } $action = $_GET['action']; function productExists($product_id) { $sql = sprintf("SELECT id FROM products "); return mysql_num_rows(mysql_query($sql)) > 0; } if($product_id && !productExists($product_id)) { die("Error. Product Doesn't Exist"); } if($action == "add" ) { $_SESSION['a'][$product_id]++; } else if ($action == "remove" ) { $_SESSION['a'][$product_id]--; } else if($action = "empty" ) { unset($_SESSION['a']); } if(isset($_SESSION['a'])){ if($_SESSION['a'][$product_id] == 0 ) { unset($_SESSION['a'][$product_id]); } } if(isset($_SESSION['a'])) { foreach($_SESSION['a'] as $product_id => $quantity) { $sql = sprintf("SELECT name, description, price, pandp FROM products WHERE id = %d;", $product_id); $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { list($name, $description, $price, $pandp) = mysql_fetch_row($result); $line_cost = $price * $quantity; if(!isset($total)) { $total = 0; } $total = $line_cost + $total; if(!isset($post)) { $post = 0; } $post = $pandp; print " <tr> <td width='66%'><span class='style2'>$name</span></td> <td width='15%' align='center' valign='middle'><span class='style2'><a href='basket.php?action=remove&id=$product_id'><img src='images/minus.jpg' alt='Remove' width='15' height='15' border='0' valign='middle' /></a> <input type='text' value='$quantity' style='width:30' /> <a href='basket.php?action=add&id=$product_id'><img src='images/plus.jpg' alt='Add' width='15' height='15' border='0' valign='middle' /></a></span></td> <td width='17%' align='right'><span class='style2'>£ $line_cost</span></td> </tr>"; } } } else { $total = 0.00; print " <tr> <td width='66%'><span class='style2'>Your Basket is Empty...</span></td> <td width='15%' align='center' valign='middle'><span class='style2'>0</span></td> <td width='17%' align='right'><span class='style2'>0.00</span></td> </tr>"; } ?> <tr> <td colspan='3' align='right' bgcolor='#E6E6E6'><span class='style2'>Shipping & Handling Included</span></td> </tr> <tr> <td colspan='3' align='right' bgcolor='#E6E6E6'><span class='style2'><strong>Total : £ <? echo $total ?></strong></span></td> </tr> </table> <a href="index.php">Continue Shopping</a> The Problem is that when you first add a product to the cart, you get the error: Notice: Undefined index: a (This being the cart session) Notice: Undefined index: 50 (This being the product id) but then if you add another, it goes away...? so the adding of additional products is fine, no errors, it's just the initial add.. any ideas...? thanks again!!
  23. Hi Guys, I just unset the session, and it seems to have done the job. think i filled it up with testing... does anyone know a way to avoid this overflow? ? ? I also need some help with error handling, will get back when i iron out the original creases Thanks Again
  24. Hi Thanks for replying! it's grown into a bit of a monster.. but here we go... <? session_start() ?> <style type="text/css"> <!-- .style1 {font-size: 24px} .style2 {font-size: 12px} .style4 {font-size: 12px; font-weight: bold; } --> </style> <p><a href="http://www.everyonlinestore.co.uk/snookereast/index.php"><img src="images/logo.jpg" alt="Snooker East" border="0" longdesc="http://www.everyonlinestore.co.uk/snookereast/index.php" /></a></p> <p class="style1">Your Shopping Basket </p> <table width='800' border='1' cellspacing='0' cellpadding='0'> <tr> <td align='left' bgcolor='#C9E4E4'><span class='style4'>Product</span></td> <td align='center' bgcolor='#C9E4E4'><span class='style4'>Quantity</span></td> <td align='center' bgcolor='#C9E4E4'><span class='style4'>Amount</span></td> </tr> <?php include("config.php"); //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die ("Could not connect to mysql because ".mysql_error()); //select the database mysql_select_db($db) or die ("Could not select database because ".mysql_error()); //if(!isset($_GET['id'])) { $_GET['id'] = " "; } $product_id = $_GET['id']; //if(!isset($_GET['action'])) { $_GET['action'] = " "; } $action = $_GET['action']; function productExists($product_id) { $sql = sprintf("SELECT id FROM products "); return mysql_num_rows(mysql_query($sql)) > 0; } if($product_id && !productExists($product_id)) { die("Error. Product Doesn't Exist"); } if($action == "add" ) { $_SESSION['a'][$product_id]++; } else if ($action == "remove" ) { $_SESSION['a'][$product_id]--; } else if($action = "empty" ) { unset($_SESSION['mycart']); } if($_SESSION['a'][$product_id] == 0 ) { unset($_SESSION['a'][$product_id]); } if($_SESSION['a']) { foreach($_SESSION['a'] as $product_id => $quantity) { $sql = sprintf("SELECT name, description, price, pandp FROM products WHERE id = %d;", $product_id); $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { list($name, $description, $price, $pandp) = mysql_fetch_row($result); $line_cost = $price * $quantity; if(!isset($total)) { $total = 0; } $total = $line_cost + $total; if(!isset($post)) { $post = 0; } $post = $pandp; print " <tr> <td width='66%'><span class='style2'>$name</span></td> <td width='15%' align='center' valign='middle'><span class='style2'><a href='basket.php?action=remove&id=$product_id'><img src='images/minus.jpg' alt='Remove' width='15' height='15' border='0' valign='middle' /></a> <input type='text' value='$quantity' style='width:30' /> <a href='basket.php?action=add&id=$product_id'><img src='images/plus.jpg' alt='Add' width='15' height='15' border='0' valign='middle' /></a></span></td> <td width='17%' align='right'><span class='style2'>£ $line_cost</span></td> </tr>"; } } } ?> <tr> <td colspan='3' align='right' bgcolor='#E6E6E6'><span class='style2'>Shipping & Handling Included</span></td> </tr> <tr> <td colspan='3' align='right' bgcolor='#E6E6E6'><span class='style2'><strong>Total : £ <? echo $total ?></strong></span></td> </tr> </table> <a href="index.php">Continue Shopping</a> It's falling over on the : if($action == "add" ) { $_SESSION['a'][$product_id]++; } else if ($action == "remove" ) { $_SESSION['a'][$product_id]--; } Thanks
×
×
  • 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.