Passing variables

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

Post Reply
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Passing variables

Post by SBro »

I have a seemingly simple piece of code that doens't seem to be working...


[configure.php]

Code: Select all

<?

include 'news.php';
include 'calendar.php';

if ($link == "news") {

   echo 'this is where the news form would go';
  
}
else if ($link == "calendar") {
   echo 'this is where the calendar form would go';
}
 
?>
[mod_edit:

Code: Select all

tag added][/size]

Basically what happens is I have one page where records for news (news.php) and calendar (calendar.php) events are displayed on the page, there is a link to add a new calendar event or a new news item. From that link i pass the variable "configure.php?link=news" (for a new news item).  When I pass this variable I want a form to be displayed at the bottom of the page.  The variable gets passed ok but the if statement doesn't seem to get executed, any ideas? thanks.
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Try

$link = $_GET['link'];

above all the other code.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

If the file names are the same as the query string, you might want to use something simpler like:

Code: Select all

<?php
$include = $_GET['link'] . ".php";
include($include);
?>
Then you can just call: index.php?link=calendar

-Nay
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if you do so you have to test thoroughly the value of $include or scripts you don't want to might be invoked.
index.php?link=..%2F..%2Fnotwebspace%2Fscripts%2FdeleteEveryThing
Post Reply