scmeeker Posted June 29, 2010 Share Posted June 29, 2010 After a person is logged in, I want to be able to keep out users(buyers) who don't have a storefront (there are buyers and sellers). So, if they don't have a store id, they can't access that area. I came up with this statement: if ($store_id < "1") { header("location:store_signup.php");} This would reroute the user to a new page. I'm having problems with where to place the code within my code. When I test it, it keeps skipping over it and if I place it before the "list($width) = getimagesize($item_photo);....." closing off the "else" bracket preceding it, it does reroute to the page I want it to but it ends the while loop, only giving me one item for users who actually do have a store. I want it to be able to continue the loop for actual sellers who have a storefront and list all their items and not just one. Any ideas?? Thanks! //validate item $get_item_sql = "SELECT p.id, p.photo, p.title, p.username, p.date, p.price, p.store_id, s.store_id, s.username FROM store AS s LEFT JOIN product AS p on s.username = p.username WHERE s.username = '".$_GET["username"]."'"; $get_item_res = mysqli_query($mysqli, $get_item_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($get_item_res) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { //valid item, get info while ($item_info = mysqli_fetch_array($get_item_res)) { $store_id = $item_info['store_id']; $item_title = stripslashes($item_info['title']); $item_username = $item_info['username']; $item_date = $item_info['date']; $item_price = $item_info['price']; $item_photo = $item_info['photo']; $content .= ""; if ($store_id < "1") { header("location:user_login.php");} list($width) = getimagesize($item_photo); // set the maximum width of the image here $maxWidth = 100; if ($width > $maxWidth); $content .= "<table width=\"603\" border=\"0\"><tr><td width=\"101\"> <img alt=\"Image\" border=0 width=\"{$maxWidth}\" src=\"{$item_photo}\" /><td width=\"201\"> {$item_title}</td> <td width=\"109\">{$item_username}</td><td width=\"101\"> {$item_date}</td><td width=\"99\"> \${$item_price} USD </td></tr></table>"; $content .= "\n"; } } Quote Link to comment https://forums.phpfreaks.com/topic/206217-where-to-insert-an-if-clause/ Share on other sites More sharing options...
waynew Posted June 29, 2010 Share Posted June 29, 2010 if ($store_id < "1") Why have you enclosed 1 in quotes? Do buyers have a store_id of 0 by default? Also, it's a good practise to put exit() after a redirect. if(condition){ header('Location: google.com'); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/206217-where-to-insert-an-if-clause/#findComment-1078898 Share on other sites More sharing options...
scmeeker Posted June 29, 2010 Author Share Posted June 29, 2010 Thanks. I'm also wondering where to place it in the code because I want the loop to continue and not end. Quote Link to comment https://forums.phpfreaks.com/topic/206217-where-to-insert-an-if-clause/#findComment-1078903 Share on other sites More sharing options...
plutomed Posted June 29, 2010 Share Posted June 29, 2010 Is the store_id field in your database an integer? If it is as waynewex said you don't need the quotes. Quote Link to comment https://forums.phpfreaks.com/topic/206217-where-to-insert-an-if-clause/#findComment-1078914 Share on other sites More sharing options...
scmeeker Posted June 30, 2010 Author Share Posted June 30, 2010 the store_id is a random integer greater than zero. So if it is set to less than 1 then the user has no store id and therefore should not have access. Then they would be redirected to a different page. Quote Link to comment https://forums.phpfreaks.com/topic/206217-where-to-insert-an-if-clause/#findComment-1078956 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.