Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

passing data in url, what happens if no data is passed

New Here ,
Aug 22, 2006 Aug 22, 2006
I am working in php with MySQL.

Some of the pages in my site require some data to be passed in the url. In most cases it is 'data_region'. If this isn't passed in the url I get an 'undefined index' error. Is there a way to say:

if 'data_region' exists use the information that it passes,
else use '?data_region=ALL'

At the moment I am just using a web forwarder on the index page to forward to the main.php with the correct data_region instead of having main.php as the index. This is OK but it sometimes takes a while, especially on slower connections.

Any help appreciated.

My code:

TOPICS
Server side applications
321
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 22, 2006 Aug 22, 2006
deadlyhifi wrote:
> I can see what you're trying to do here but it isn't working because it is
> still looking for '?data_region' in the URL. I need it to apply
> 'data_region=ALL' when 'data_region' is not mentioned in the URL.

In that case, put this at the top of your page:

if (!isset($_GET['data_region']) $_GET['data_region'] = 'ALL';

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
LEGEND ,
Aug 22, 2006 Aug 22, 2006
deadlyhifi wrote:
> Is there a way to say:
>
> if 'data_region' exists use the information that it passes,
> else use '?data_region=ALL'

Yes, there is. Dreamweaver should take care of this for you, but the
recordset code ignores the default value.

Change the following section from this:

> $region = "ALL";
> if (isset($_GET['data_region'])) {
> $colname_rs_video = (get_magic_quotes_gpc()) ? $_GET['data_region'] :
> addslashes($_GET['data_region']);
> }

To this:

$region = "ALL";
if (isset($_GET['data_region'])) {
$colname_rs_video = (get_magic_quotes_gpc()) ? $_GET['data_region']
: addslashes($_GET['data_region']);
}
else {
$colname_rs_video = "ALL";
}

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 22, 2006 Aug 22, 2006
Thanks for your reply.

I can see what you're trying to do here but it isn't working because it is still looking for '?data_region' in the URL. I need it to apply 'data_region=ALL' when 'data_region' is not mentioned in the URL.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 22, 2006 Aug 22, 2006
deadlyhifi wrote:
> I can see what you're trying to do here but it isn't working because it is
> still looking for '?data_region' in the URL. I need it to apply
> 'data_region=ALL' when 'data_region' is not mentioned in the URL.

In that case, put this at the top of your page:

if (!isset($_GET['data_region']) $_GET['data_region'] = 'ALL';

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 22, 2006 Aug 22, 2006
you Monsieur Powers deserve an award.

don't forget the extra ')' though...

if (!isset($_GET['data_region'])) $_GET['data_region'] = 'all';
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 22, 2006 Aug 22, 2006
LATEST
deadlyhifi wrote:
> you Monsieur Powers deserve an award.

Merci.

> don't forget the extra ')' though...

Just testing. ;)

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines