freelanceprogrammers.org Forum Index » PHP

New to php


View user's profile Post To page top
hd85flt Posted: Fri Nov 25, 2005 2:56 am


Joined: 25 Nov 2005

Posts: 1
New to php
I`m crossing over from ColdFusion and I use a database to deliver
content based on "pageName". I would like to test for page name and if
it doesn`t exist, reload the default page content. I find my sites
work until I type a url string that doesn`t exist in the database,
then I get sql errors on the page for navigation results
because "parentID is "null". Its so easy in ColdFusion but I just
don`t get it here...
Reply with quote
Send private message
View user's profile Post To page top
jrsofty Posted: Fri Nov 25, 2005 1:34 pm


Joined: 22 Nov 2005

Posts: 2
New to php
Hi there,

I`m gathering from your question you are looking to test the variable
pageName from the url like:

http://www.yoursite.com/index.php?pageName=smoke

and if there is no pageName then set load the default. Personally I
would right it like this.

if(isset($_GET[`pageName`])){
// load the requested page
}else{
// load the default page
}

The $_GET variable is a Superglobal that breaks down the request of
the GET (everything after the ? in the URL). If you are unsure if this
comes from the GET method you can also use the superglobal $_REQUEST
which is another array that handles both GET and POST methods.

You check to see if the array element is actually given a value using
the isset() function. If you attempted an is_null() function and there
is no element then PHP will throw a warning.

I hope this helps you on your way.
--- In php-objects@yahoogroups.com, "hd85flt" <hd85flt@y...> wrote:
>
> I`m crossing over from ColdFusion and I use a database to deliver
> content based on "pageName". I would like to test for page name and if
> it doesn`t exist, reload the default page content. I find my sites
> work until I type a url string that doesn`t exist in the database,
> then I get sql errors on the page for navigation results
> because "parentID is "null". Its so easy in ColdFusion but I just
> don`t get it here...
>
Reply with quote
Send private message
View user's profile Post To page top
lucius_decrius Posted: Fri Nov 25, 2005 5:31 pm


Joined: 02 May 2005

Posts: 7
New to php
I think thats not the problem, I think the problem is he tries to select
the page from the database, but the page does not exists on the database.
You should write a method to test if the page exists in the database
before trying to display it.

if(isset($_GET[`pageName`]) && pageExists($_GET[`pageName`])){
// load the requested page
}else{
// load the default page
}

function pageExists($pageName) {
$sql = "select count(*) from table where page_name = `$pageName`";
if (RDBMS_query($sql)) {
return true;
} else {
return false;
}
}

Eduardo

Jason Reed wrote:

> Hi there,
>
> I`m gathering from your question you are looking to test the variable
> pageName from the url like:
>
> http://www.yoursite.com/index.php?pageName=smoke
>
> and if there is no pageName then set load the default. Personally I
> would right it like this.
>
> if(isset($_GET[`pageName`])){
> // load the requested page
> }else{
> // load the default page
> }
>
> The $_GET variable is a Superglobal that breaks down the request of
> the GET (everything after the ? in the URL). If you are unsure if this
> comes from the GET method you can also use the superglobal $_REQUEST
> which is another array that handles both GET and POST methods.
>
> You check to see if the array element is actually given a value using
> the isset() function. If you attempted an is_null() function and there
> is no element then PHP will throw a warning.
>
> I hope this helps you on your way.
> --- In php-objects@yahoogroups.com, "hd85flt" <hd85flt@y...> wrote:
> >
> > I`m crossing over from ColdFusion and I use a database to deliver
> > content based on "pageName". I would like to test for page name and if
> > it doesn`t exist, reload the default page content. I find my sites
> > work until I type a url string that doesn`t exist in the database,
> > then I get sql errors on the page for navigation results
> > because "parentID is "null". Its so easy in ColdFusion but I just
> > don`t get it here...
> >
>
>
>
>
>
>
> PHP Data object relational mapping generator -
> http://www.meta-language.net/
>
>
> ------------------------------------------------------------------------
> YAHOO! GROUPS LINKS
>
> * Visit your group "php-objects
> <http://groups.yahoo.com/group/php-objects>" on the web.
>
> * To unsubscribe from this group, send an email to:
> php-objects-unsubscribe@yahoogroups.com
> <mailto:php-objects-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------------------------------------------------
>


[Non-text portions of this message have been removed]
Reply with quote
Send private message
View user's profile Post To page top
tech@... Posted: Fri Nov 25, 2005 9:49 pm


Joined: 27 Apr 2005

Posts: 7
New to php
I would add another construct, which will give you more flexibility in the
future:

switch($_GET[`pageName`]) { //if you`re not sure how the variable will pass
use $_REQUEST[`pageName`]

case ``:
//load requested page
break;

case ``:
//do something else
break;

default:
//function or load default page
break;
}

-----Original Message-----
From: php-objects@yahoogroups.com [mailto:php-objects@yahoogroups.com] On
Behalf Of Jason Reed
Sent: Friday, November 25, 2005 2:35 AM
To: php-objects@yahoogroups.com
Subject: [php-objects] Re: New to php

Hi there,

I`m gathering from your question you are looking to test the variable
pageName from the url like:

http://www.yoursite.com/index.php?pageName=smoke

and if there is no pageName then set load the default. Personally I would
right it like this.

if(isset($_GET[`pageName`])){
// load the requested page
}else{
// load the default page
}

The $_GET variable is a Superglobal that breaks down the request of the GET
(everything after the ? in the URL). If you are unsure if this comes from
the GET method you can also use the superglobal $_REQUEST which is another
array that handles both GET and POST methods.

You check to see if the array element is actually given a value using the
isset() function. If you attempted an is_null() function and there is no
element then PHP will throw a warning.

I hope this helps you on your way.
--- In php-objects@yahoogroups.com, "hd85flt" <hd85flt@y...> wrote:
>
> I`m crossing over from ColdFusion and I use a database to deliver
> content based on "pageName". I would like to test for page name and if
> it doesn`t exist, reload the default page content. I find my sites
> work until I type a url string that doesn`t exist in the database,
> then I get sql errors on the page for navigation results because
> "parentID is "null". Its so easy in ColdFusion but I just don`t get it
> here...
>






------------------------ Yahoo! Groups Sponsor --------------------~-->
1.2 million kids a year are victims of human trafficking. Stop slavery.
http://us.click.yahoo.com/WpTY2A/izNLAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->

PHP Data object relational mapping generator - http://www.meta-language.net/
Yahoo! Groups Links
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help