Jump to content

if ($action==members){$thispage="Members";} Problem, please help :).


Technex

Recommended Posts

On my website I have a code like this where if $thispage='test'; then it would echo in the page title "(Ti|test".

 

I have this for index.php

$action = $_GET['action'];

if ($action==NULL){

$thispage="Homepage";

}

 

Which works fine.

 

but say for

 

?action=members

 

this should work right?

 

$action = $_GET['action'];

if ($action==members){

$thispage="Members";

}

 

But all it outputs in page title is nothing like this: "(Ti|"

Firstly, when doing "if", "else" statements, the only time you don't use quote marks around the bit you're asking if it looks like - in this case "members", is if it's an interger (a number). Otherwise it should always have quote marks. Therefore the code should read:

 

$action=$_GET['action'];

if ($action=="members") {

$thispage="Members";

}

 

But if I were you, i'd lose the $action=$_GET['action'] line, unless you refer to $action more in the file, as it's just a wasted line. So that would leave...

 

if ($_GET['action']=="members") {

$thispage="Members";

}

 

If you find this isn't working, then it's probably a problem with the $_GET['members'] variable (try just echoing it and see what it says to ensure you're spelling it right etc.).

if there are a lot of values 'action' can take then a switch would be better

 

switch(trim($_GET['action']))
{
case 'members':
  $thispage="Members";
  break;
case 'freaks':
  $thispage="Cook Book";
  break;
case 'noodles':
  $thispage="Cannibalism for Beginners";
  break;
default:
  $thispage="Soft Porn Extravaganza!";
}

The man has a point. Also, going back to the original method aswell. If the echo is showing that $_GET['action'] has a value "members", then the...

 

if ($_GET['action']=="members") {

$thispage="Members";

}

 

Should work, and perhaps it's the other part of the page that isn't. To test it out, try adding this line under the above part.

 

echo $thispage;

 

If the if statement is working, it should come out with "Members" somewhere.

 

Whereas that case code is used elsewhere in my site, I don't think it's the right in this case, it seems like bloted code. Unless I can just add this to index.php and be done with it?

 

 

 

echo $thispage; = Members

 

@ dooper

 

So it should work!

 

Thanks for the help guys :).

Bump, thank you guys/gals :).

 

I'll try the case method now but I don't think it'll work.

 

/edit. I got it to work, I thought as the index.php is always included why not just use it there. It works :).

 

Thanks guys, I'll put the case method in anyway as it's faster correct? (as it's now on one page)

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.