Jump to content

help withsyntax for if else statement


John T

Recommended Posts

Hi, I am creating a genealogy website using The Next Generation Software. Access to the site will  require the users to log in, they will also be assigned a tree. It will have two family history trees. At the moment it is on a local wamp server.

My question is: I have two custompages, page1.php and page2.php.

I only want users assigned to tree1 to be able to see page1.php and users assigned to tree2 only to be able to see page2.php.

I think I need an if else statement on each of the two pages or, they could be directed there from a welcome.php page. but as I have no knowledge of php I am clueless as to how or what to put in the if else statement and where it should go.

I have googled php syntax and seen lots of code but they all seem to use “echo” but I do not need print anything just, go to  certain pages.

I have seen the following in various pages of code used in the program if it helps-

include($cms['tngpath'] ."checklogin.php");

$assignedtree = $_SESSION['assignedtree'];

$currentuser = $_SESSION['currentuser'];

Any help would be appreciated many thanks for reading this.

Regards,

John.

Link to comment
Share on other sites

Do you mean something like:

 

$assignedtree = $_SESSION['assignedtree'];
$currentuser = $_SESSION['currentuser'];

if($assignedtree == 'tree1')
{
   echo $currentuser  . ' is looking at tree 1';
}
elseif($assignedtree == 'tree2')
{
   echo $currentuser  . ' is looking at tree 2';
}
else
{
   echo $currentuser . ' did not match either tree';
}

 

Replacing the tree1 and tree2 with whatever you're storing in the session.

Link to comment
Share on other sites

Hi Veteah thanks for the reply.

 

I think you are on the way to fixing this. The only thing is I do not need the echo part.

Insted I would like the specific page to open, either page1.php or page2.php

 

It is so frustrating not knowing php.

Link to comment
Share on other sites

Veteah, I am not used to getting replies this quick from a forum, thanks so much.http://www.phpfreaks.com/forums/Smileys/nrg_alpha/happy-01.gif

I will give this a try and let you know.

Might be tomorrow as I am just off out.

Regards,

 

John

Link to comment
Share on other sites

Hi Veteah,

I tried the echo statement first to see the result and it was as expected, showed who was logged in and their tree.

Then I tried the include statement and got parse errors.

The below is the start of my page up to your code. It shows different things I have tried and the parse errors.

Thanks,

John

 

<?php

 

include( "../begin.php"); 

if( !$cms['support'] )

$cms['tngpath'] = "../";

include($cms['tngpath'] ."genlib.php");

include($cms['tngpath'] ."getlang.php");

include($cms['tngpath'] ."$mylanguage/text.php");

include ($cms['tngpath'] ."checklogin.php");

include($cms['tngpath'] . "log.php" );

tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;

$logstring = "<a href=\"extrapgs/welcome.php\"welcome</a>";

writelog($logstring);

preparebookmark($logstring);

// ****************************** NEW CODE FROM Veteah ********************

$assignedtree = $_SESSION['assignedtree'];

$currentuser = $_SESSION['currentuser'];

 

if($assignedtree == 'tree1')

{

echo $currentuser  . ' is looking at tree 1'; // echo is showing who is signed in and which tree is being looked at.

// include ($cms['tngpath'] . 'cuttingshome.php'};  // If I add  ($cms['tngpath'] results in parse error line 22 (this line)

// include  . ('cuttingshome.php'};                  // if I use single quotes results in parse error line 23 (this line)

// include  . ("cuttingshome.php"};                  // if I use double quotes results in parse error line 24 (this line)

 

}

elseif($assignedtree == 'tree_2')

{

  echo $currentuser  . ' is looking at tree 2';      // echo is showing who is signed in and which tree is being looked at.

}

else

{

  echo $currentuser . ' did not match either tree';  // This also works

}

/*In that case, all you have to do is add

 

include('file_path');

... where the echo is. */

//  ************************* END OF NEW CODE FROM Veteah ******************************

Link to comment
Share on other sites

  • 2 weeks later...

Hi Veteah and thanks for pointing me in the right direction

All is now sorted with this, the echo statement only needed a page link.

For those interested in the result the code is below.

 

$assignedtree = $_SESSION['assignedtree'];

$currentuser = $_SESSION['currentuser'];

<?php    if ($assignedtree == 'tree1') {

echo '<a href=\'page1.php\'>Page Title</a>';

}

elseif ($assignedtree == 'tree_2')

{

echo '<a href=\'page2.php\'>another page title</a>';

}

else

{

    echo 'You don\'t have a user account Please register';

 

}

?>

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.