[solved] simple isset problem

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
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

[solved] simple isset problem

Post by seeker2921 »

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]


hello, i've pretty much forgoten everything i knew about php since i havent used it in years. i know this is simple but i was woundering if someone could help me out.. heres what im trying to do

myurl.com/index.php?id=gallery

now when this is entered the page i need it to include a seperate php file into my template heres the code ive tried

Code: Select all

<?
if(!isset($id)){
include('/home/stephen/public_html/site/blog/index.php');
}
elseif($id==($links))
{
include('$links');
}
?>

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 seeker2921 on Mon Sep 04, 2006 12:18 pm, edited 1 time in total.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Maybe you want to check against $_GET['id'] rather than $id.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

i tried setting $id=($_get['id'])} in attempt to correct it earlyer. didnt work, see the first half of the code works fine. its when i add the id in the url it mess' up.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Useful Posts references a thread you may find of interest.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

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]


thanks feyd, i went there and found a useful post. i tried this code

Code: Select all

<?
if (in_array($_GET['id'],$url)) {
   include $_GET['id'];
} else {
   include('/home/stephen/public_html/site/blog/index.php');
} 
?>
now what happens is regrdless if i go to domain.com/index.php or domain.com/index.php?id=gallery it shows the blog


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]
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

i know this is a simple problem.. i just dont see what im doing wrong, ive looked at php.net and tried stuff from there still no luck..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What is $url?
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

$url is my array that has all the locations of the include files
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Will this work for you at all?

Code: Select all

<?php
$id = 0;
if (isset($_GET['id']))
{
    $id = $_GET['id'];
}

if (0 != $id) {
    include '/home/stephen/public_html/site/blog/index.php';
} else {
    include $links;
}
?>
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

i tired it, no luck. I then tried this code it did fine the first part but when i added the main.php?id=gallery it gave me this error message

Warning: main($links): failed to open stream: No such file or directory in /home/stephen/public_html/main.php on line 160

Warning: main($links): failed to open stream: No such file or directory in /home/stephen/public_html/main.php on line 160

Warning: main(): Failed opening '$links' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/stephen/public_html/main.php on line 160

heres the code i used

Code: Select all

<? 
if(!isset($id)){
include('/home/stephen/public_html/site/blog/index.php');
} 
else 
{ 
    for($i=0; $i<count($url); $i++) 
    { 
        if($id==$links[$i]) 
        { 
            include('$links');
            break; 
        } 
    } 
} 
?>
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

i messed around with what i had up above and now it works.. thanks for the help guys..

heres the code that works

Code: Select all

<?
if(!isset($id)){
include('/home/stephen/public_html/site/blog/index.php');
}
else
{
    for($i=0; i<count($links); $i++)
    {
        if($id==$links[$i])
        {
            include($url[$i]);
            break;
        }
    }
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Single quote strings are string literals. They do not parse any variables inside of them. In this particular case, you don't need quotes at all. However, apparently $links is an array.
Post Reply