jose07 Posted November 8, 2010 Share Posted November 8, 2010 Hey guys here is where i'm stuck: i have adverts on the site but i have set permission on the adverts to be either 'public' or 'restricted' so based on that i want to create a statement with three possible outcomes, it should check the values of the columns and if the is an advert it will check the permission if the permission 0 (public) it shows the ad if permission 1 (restricted) it will direct the user to a log-in page however if the user is logged on then it will just show all the adverts. These is the code i'm using but it is only executing the else line (so when the user clicks on the ad it takes them straight to the login page even if the ad is set to '0')....i checked the error log and i get the msg :PHP Notice: Undefined variable: SiteDir in code: <?php $qry_getAdverts = mysql_query("SELECT advertID,accesslevelID FROM adverts_adverts"); $row_getAdvert = mysql_fetch_assoc($qry_getAdverts); if($qry_getAdverts["AdvertID"] > 0 && ($qry_getAdverts["accesslevelID"] == 0 )) { echo($row_getAdvert["Content"]); } else { echo '<script type="text/javascript ">window.location.href=\'' . $SiteURL . '/my-account/login.php\';</script>' ; } ?> I tried put it as an array and use a while loop but still it didn't work Any tips much appreciated! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/218135-conditional-statments-array/ Share on other sites More sharing options...
trq Posted November 9, 2010 Share Posted November 9, 2010 if($qry_getAdverts["AdvertID"] > 0 && ($qry_getAdverts["accesslevelID"] == 0 )) { should be.... if($row_getAdverts["AdvertID"] > 0 && ($row_getAdverts["accesslevelID"] == 0 )) { Quote Link to comment https://forums.phpfreaks.com/topic/218135-conditional-statments-array/#findComment-1132062 Share on other sites More sharing options...
jose07 Posted November 9, 2010 Author Share Posted November 9, 2010 Hi, Thanks very much for the reply, unfortunately i still can't get it to work as it seems it doesn't recognise the accesslevel and if it displays it displays all adverts and if it doens't display it doesn't display any advert which is obv showing that the accesslevelID param is not being recognised. I have attached the whole page so you can have a look and maybe spot the error. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/218135-conditional-statments-array/#findComment-1132078 Share on other sites More sharing options...
jose07 Posted November 10, 2010 Author Share Posted November 10, 2010 have another question I can't user headers because the script already uses other set headers which then conflict if i add another one on the if statement. my question is how can i direct the user to a particular page 'login' from the if statement without using javascript or headers? and if i have to use header how do i set it up so it doesn't conflict with the others already set? else { //echo '<script type="text/javascript">window.location.href=\'' . $SiteURL . '/my-account/login.php\';</script>'; header("location: {$SiteURL}/my-account/login.php"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/218135-conditional-statments-array/#findComment-1132486 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.