phpanon Posted March 6, 2008 Share Posted March 6, 2008 Hello, I have a problem with my loop, i think its to do if statement I have at the start because it is going straight to the else statement even when the basket has items in it. Want I want it to do is, if the basket is empty then show " there are no products..." But at the moment it is doing that even when it isn't empty. <?php require "connect.php"; $empID = $_SESSION['empID']; $username = $_SESSION['username']; if($_SESSION['basket'] == !null) { $query = "insert into orders values ('','".$empID."','".$username."','".date("d-M-Y")."')"; @mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); $order_id = mysql_insert_id(); foreach($_SESSION['basket'] as $key => $product) { $query2 = "insert into productorder values ($order_id,'".$_SESSION['basket'][$key]['URN']."','".$_SESSION['basket'][$key]['quantity']."','Awaiting Approval')"; @mysql_query($query2, $connection) or die ("Unable to perform query<br>$query2"); } unset($_SESSION['basket']); $message2 = "Order has successfully been submitted"; header("Location: StationaryBasket.php"); exit(); } else { $message1 = "There are no products in the Stationary Basket"; header("Location: StationaryBasket.php?message1=$message1"); exit(); } ?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 6, 2008 Share Posted March 6, 2008 Change: if($_SESSION['basket'] == !null) to: if(isset($_SESSION['basket']) && !empty($_SESSION['basket'])) Quote Link to comment Share on other sites More sharing options...
phpanon Posted March 6, 2008 Author Share Posted March 6, 2008 Hi, I tried your suggestion... but still gettin the message "No products...." even when there are. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 6, 2008 Share Posted March 6, 2008 Have you started the session? I did not see any call to session_start(); in your code. Quote Link to comment Share on other sites More sharing options...
phpanon Posted March 6, 2008 Author Share Posted March 6, 2008 ah yes, amateur mistake. Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.