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(); } ?> Link to comment https://forums.phpfreaks.com/topic/94772-loop-problems/ 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'])) Link to comment https://forums.phpfreaks.com/topic/94772-loop-problems/#findComment-485280 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. Link to comment https://forums.phpfreaks.com/topic/94772-loop-problems/#findComment-485284 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. Link to comment https://forums.phpfreaks.com/topic/94772-loop-problems/#findComment-485286 Share on other sites More sharing options...
phpanon Posted March 6, 2008 Author Share Posted March 6, 2008 ah yes, amateur mistake. Thank you Link to comment https://forums.phpfreaks.com/topic/94772-loop-problems/#findComment-485295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.