Skip to main content
Participant
August 22, 2006
Answered

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

  • August 22, 2006
  • 1 reply
  • 352 views
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:

This topic has been closed for replies.
Correct answer Newsgroup_User
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/

1 reply

Inspiring
August 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/
Participant
August 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.