Jump to content

conditional statments & array


jose07

Recommended Posts

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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();

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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