Page 1 of 1

Passing variables

Posted: Wed Oct 08, 2003 10:45 pm
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.

Posted: Wed Oct 08, 2003 10:57 pm
by Paddy
Try

$link = $_GET['link'];

above all the other code.

Posted: Wed Oct 08, 2003 11:11 pm
by volka

Posted: Wed Oct 08, 2003 11:39 pm
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

Posted: Wed Oct 08, 2003 11:43 pm
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