Basic variable-parameter issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
fwc
Forum Newbie
Posts: 23
Joined: Fri Jul 13, 2007 4:55 am

Basic variable-parameter issue

Post by fwc »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi, I am a new programmer and having some issues with my PHP website.  I am a gigantic nooby so please have pity on me.

Code: Select all

<?php
include ('db_config.php');

include ('header.php');
	echo "<p>YEA</p>";
	echo "<a href=/eclipse_projects/?page=about>About</a><br>";
	include ('footer.php');

if ($page == 'about')
{
	include ('header.php');
	echo "<p>We're the <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>!</p>";
	echo "<a href=/eclipse_projects/?page=home>Home</a>";
include ('footer.php');
}
?>
When I click on the link it doesn't send me to the new page, it reloads the same one with different parameters. Can someone please help :)
I'm running this in WAMP if that helps
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by fwc on Mon Aug 06, 2007 10:59 pm, edited 3 times in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: I'm sorry I'm such a nub

Post by superdezign »

fwc wrote:please have pity on me.
No. :P
Pity is for losers.
fwc wrote:

Code: Select all

if ($page == 'about')
Where do you set $page?
You're likely after $_GET['page'].
User avatar
fwc
Forum Newbie
Posts: 23
Joined: Fri Jul 13, 2007 4:55 am

Re: I'm sorry I'm such a nub

Post by fwc »

superdezign wrote:
fwc wrote:please have pity on me.
No. :P
Pity is for losers.

fwc wrote:

Code: Select all

if ($page == 'about')
Where do you set $page?
You're likely after $_GET['page'].
Just a little pity?

Ok thanks, I'll try
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

All if your page is going to run, meaning if you do get the about page, you're going to have header - content - footer, header - content - footer (two times).

You need a switch, if/else/elseif, die(), exit, or something.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
aileenguan
Forum Newbie
Posts: 3
Joined: Sun Aug 05, 2007 10:52 pm
Location: P.R.C.

Post by aileenguan »

you should use $_GET['page']
User avatar
fwc
Forum Newbie
Posts: 23
Joined: Fri Jul 13, 2007 4:55 am

Post by fwc »

scottayy wrote:All if your page is going to run, meaning if you do get the about page, you're going to have header - content - footer, header - content - footer (two times).

You need a switch, if/else/elseif, die(), exit, or something.
Thanks very much

If I were to use die or exit, where would I put them?
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

fwc wrote:
scottayy wrote:All if your page is going to run, meaning if you do get the about page, you're going to have header - content - footer, header - content - footer (two times).

You need a switch, if/else/elseif, die(), exit, or something.
Thanks very much

If I were to use die or exit, where would I put them?
I don't think you really need die or exit for what your trying to do, i think he was just giving you some options, but, your main concern is setting $page, which obviously isnt being done. So your code, with an ELSEIF (for example) would look more like this.

Code: Select all

<?php 
// The linked you clicked on what something like 'mysite.com?page=about'

include ('db_config.php'); 

$page = $_GET['page']; // You need this somewhere before your IF statement 

if ($page == 'about') 
{
include ('header.php'); 
        echo "<p>YEA</p>"; 
        echo "<a href=/eclipse_projects/?page=about>About</a><br>"; 
        include ('footer.php'); 
}

elseif ($page == 'anotherPage') 
{ 
        include ('header.php'); 
        echo "<p>We're the smurf!</p>"; 
        echo "<a href=/eclipse_projects/?page=home>Home</a>"; 
include ('footer.php'); 
} 
?>
User avatar
fwc
Forum Newbie
Posts: 23
Joined: Fri Jul 13, 2007 4:55 am

Post by fwc »

Ok new question,

If I do it that way, when i run index.php nothing runs, i have to put in parameters for my homepage. Is this the usual practice or is there any way around it?
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

nothing runs as in 100% completely white screen??

If so, syntax error (I think) most likely, you may have missed a semicolon at the end of a line, a bracket somewhere, or maybe a curly brace. If you can't see it anywhere after a while, post it up, might just need a fresh pair of eyes.
User avatar
fwc
Forum Newbie
Posts: 23
Joined: Fri Jul 13, 2007 4:55 am

Post by fwc »

iknownothing wrote:nothing runs as in 100% completely white screen??

If so, syntax error (I think) most likely, you may have missed a semicolon at the end of a line, a bracket somewhere, or maybe a curly brace. If you can't see it anywhere after a while, post it up, might just need a fresh pair of eyes.
nono, sorry, I meant just a white screen.
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

huh? so you saying its a completely white screen?

echo something, whatever, just a bogus string, outside of any if statemnet and all, if nothing happens, refer to my post above again.
User avatar
fwc
Forum Newbie
Posts: 23
Joined: Fri Jul 13, 2007 4:55 am

Post by fwc »

I understand why its white, I just wanted to know if there is anyway to make a homepage without the variables and parameters, just make it index.php
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

so when you type in your domain (eg. http://youdomain.com), does index.php not come up??

If thats whats happening (I'm not sure, because I'm pretty confused) then you need to set your index's in Plesk/CPanel, or whatever other back-end control panel you have. Most likely, the only ones currently set are index.html and/or index.htm
User avatar
fwc
Forum Newbie
Posts: 23
Joined: Fri Jul 13, 2007 4:55 am

Post by fwc »

iknownothing wrote:so when you type in your domain (eg. http://youdomain.com), does index.php not come up??

If thats whats happening (I'm not sure, because I'm pretty confused) then you need to set your index's in Plesk/CPanel, or whatever other back-end control panel you have. Most likely, the only ones currently set are index.html and/or index.htm
its ok, ill figure it out
User avatar
fwc
Forum Newbie
Posts: 23
Joined: Fri Jul 13, 2007 4:55 am

Post by fwc »

While I'm at it can someone please explain the syntax

Code: Select all

->
Ok, thanks
Post Reply