Jump to content
xisto Community
Sign in to follow this  
Florisjuh

Cant Get A Script To Work PHP

Recommended Posts

I've been trying to get my website urls to work with an variable in the url to navigate. The script I use is:

 <?php  switch ($page) {  case "home":  	include home.php;  	break;  case "members":  	include members.php;  	break;  case "diplomacy":  	include diplomacy.php;  	break;  case "scrims":  	include scrims.php;  	break;  case "forums":  	include forums.php;  	break;  default:  	include home.php;  	break;  }	;?>
And I specify the hyperlinks as index.php?page=home etc
But it doesnt work, am I doing something rong in this script?

Share this post


Link to post
Share on other sites

Don't understand half the script, but the first thing I would do is put speech marks or apostrophes round the include statements. Eg:

include bla.php;

Becomes.....

include "bla.php";

What kind of error do you get?

Share this post


Link to post
Share on other sites

i use a little bit of php and lots of html, html is so much easier for stuff. so i use html for mostly all of the stuff including the navigation. i know hardly anything about php i might learn it one day but not sure. Is using php better or something?

Notice from BuffaloHELP:
Do not go off topic.
Edited by BuffaloHELP (see edit history)

Share this post


Link to post
Share on other sites

Ah! Exactly what I was trying to do a few weeks ago-You have to use the 'get' function to get the URL in the address bar first-I don't remember how to do it exactly, but browse the PHP programming section.That's the 'crucial' part you're missing. But on the other hand, good work with the cases- just won't work here :PPanda

Share this post


Link to post
Share on other sites

Try something like this:

<?php  switch ($_GET['page']) {  case "members":  	include 'members.php';  	break;  case "diplomacy":  	include 'diplomacy.php';  	break;  case "scrims":  	include 'scrims.php';  	break;  case "forums":  	include 'forums.php';  	break;  default:  	include 'home.php';  	break;  }?>

I hope that helps!

Share this post


Link to post
Share on other sites

Omg, sorry, I overlooked one more thing, the "include" part is actually a function, so it should have the () brackets.. Also, you should use the require() or require_once() functions when doing what you're doing, something like this:

require( 'members.php' );

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.