Page 1 of 2

Basic variable-parameter issue

Posted: Sun Aug 05, 2007 11:04 pm
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]

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

Posted: Sun Aug 05, 2007 11:12 pm
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'].

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

Posted: Sun Aug 05, 2007 11:15 pm
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

Posted: Mon Aug 06, 2007 12:10 am
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.

Posted: Mon Aug 06, 2007 12:13 am
by aileenguan
you should use $_GET['page']

Posted: Mon Aug 06, 2007 4:49 am
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?

Posted: Mon Aug 06, 2007 5:18 am
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'); 
} 
?>

Posted: Mon Aug 06, 2007 10:57 pm
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?

Posted: Mon Aug 06, 2007 11:03 pm
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.

Posted: Mon Aug 06, 2007 11:10 pm
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.

Posted: Mon Aug 06, 2007 11:17 pm
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.

Posted: Mon Aug 06, 2007 11:24 pm
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

Posted: Mon Aug 06, 2007 11:41 pm
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

Posted: Mon Aug 06, 2007 11:48 pm
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

Posted: Tue Aug 07, 2007 12:12 am
by fwc
While I'm at it can someone please explain the syntax

Code: Select all

->
Ok, thanks