Jump to content

where to insert an "if" clause


scmeeker

Recommended Posts

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";
  
}

  }

Link to comment
https://forums.phpfreaks.com/topic/206217-where-to-insert-an-if-clause/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.