newbie: Variables in HTML link

newbie: Variables in HTML link

am 07.04.2008 11:19:28 von Sakari Aaltonen

I'm reading an introductory book on PHP (circa 2003), where an example
contains an HTML link like
http://do_something.php?id=55

Apparently, this should set the PHP variable $id to a value (here, 55),
because do_something.php contains code like
if(20>$id) {
..........
?>

But this never works, because the variable $id is always blank (in
do_something.php), in other words, it has *not* been set to a value.

Can anyone explain what is going on, or give me a keyword? I'm a
complete newbie and do not even know what the id in the HTML link
should be called in PHP-speak. Argument? Parameter?

(My setup is openSUSE 10.3 Linux, Apache2 and PHP5.2.5.)

Thank you!

Re: newbie: Variables in HTML link

am 07.04.2008 11:46:02 von Erwin Moller

Sakari Aaltonen schreef:
> I'm reading an introductory book on PHP (circa 2003), where an example
> contains an HTML link like
> http://do_something.php?id=55
>
> Apparently, this should set the PHP variable $id to a value (here, 55),
> because do_something.php contains code like
> > if(20>$id) {
> ..........
> ?>
>
> But this never works, because the variable $id is always blank (in
> do_something.php), in other words, it has *not* been set to a value.
>
> Can anyone explain what is going on, or give me a keyword? I'm a
> complete newbie and do not even know what the id in the HTML link
> should be called in PHP-speak. Argument? Parameter?
>
> (My setup is openSUSE 10.3 Linux, Apache2 and PHP5.2.5.)
>
> Thank you!

Hi,

do_something.php?id=55 will populate the GET array.
You can find the passed values like this:
$passedid = $_GET["id"];

Maybe your book assumes old bad settings in php.ini that automake
variables passed in the GET/POST/COOKIE in the global scriptscope, which
I will not even name here.

Start using the $_GET[] and $_POST[] right now, and you'll see your
passed information. :-)

Regards,
Erwin Moller

Re: newbie: Variables in HTML link

am 07.04.2008 11:48:07 von Courtney

Sakari Aaltonen wrote:
> I'm reading an introductory book on PHP (circa 2003), where an example
> contains an HTML link like
> http://do_something.php?id=55
>
> Apparently, this should set the PHP variable $id to a value (here, 55),
> because do_something.php contains code like
> > if(20>$id) {
> ..........
> ?>
>
> But this never works, because the variable $id is always blank (in
> do_something.php), in other words, it has *not* been set to a value.
>
> Can anyone explain what is going on, or give me a keyword? I'm a
> complete newbie and do not even know what the id in the HTML link
> should be called in PHP-speak. Argument? Parameter?
>
> (My setup is openSUSE 10.3 Linux, Apache2 and PHP5.2.5.)
>
> Thank you!

The ?id=55 bit on e URL sets a variable in the global $_GET[] array.

so preface your code snippet with:

$id=$_GET['id'];

and it will work as you want.

Re: newbie: Variables in HTML link

am 07.04.2008 11:51:47 von piotr

Sakari Aaltonen wrote:
> I'm reading an introductory book on PHP (circa 2003), where an example
> contains an HTML link like
> http://do_something.php?id=55
>
> Apparently, this should set the PHP variable $id to a value (here, 55),
> because do_something.php contains code like
> > if(20>$id) {
> ..........
> ?>
>
> But this never works, because the variable $id is always blank (in
> do_something.php), in other words, it has *not* been set to a value.
>
> Can anyone explain what is going on, or give me a keyword? I'm a
> complete newbie and do not even know what the id in the HTML link
> should be called in PHP-speak. Argument? Parameter?
>
> (My setup is openSUSE 10.3 Linux, Apache2 and PHP5.2.5.)
>
> Thank you!

Nowadays, you should check for $_GET['id'] variable, when it comes in
like in your example. This is current default PHP behavior and it's
better then the old one, that I wont mention.

Take a look at
http://www.php.net/manual/en/language.variables.predefined.p hp

best regards
Piotr Nastaly

Re: newbie: Variables in HTML link

am 07.04.2008 12:31:38 von Hans-Peter Sauer






> I'm reading an introductory book on PHP (circa 2003), where an example
> contains an HTML link like
> http://do_something.php?id=55
>
> Apparently, this should set the PHP variable $id to a value (here, 55),
> because do_something.php contains code like
> > if(20>$id) {
> ..........
> ?>
>
> But this never works
>

$burp=$_REQUEST['id'];
if ($burp>20) {print "OK ITS MORE THAN 20
";}
?>


Or if you want it to be a exact match ....

$burp=$_REQUEST['id'];
if ($burp==55) {print "EXACT MATCH FOR 55
";}
?>


You can also use something like this if wanted .....

$burp=$_REQUEST['id'];
if ($burp>0 && <100) {print "TWIN CONDITIONS MATCHED OK
";}
?>

This means that $burp needs to be between 1-99 for it to be recognised
and print "TWIN CONDITIONS MATCHED OK" .


--
www.krustov.co.uk

Re: newbie: Variables in HTML link

am 07.04.2008 13:05:31 von Sakari Aaltonen

In article <47f9ed56$0$14350$e4fe514c@news.xs4all.nl>,
Erwin Moller wrote:
>do_something.php?id=55 will populate the GET array.
>You can find the passed values like this:
>$passedid = $_GET["id"];
>
>Maybe your book assumes old bad settings in php.ini


Thank you - $_GET solved the problem. It seems I'll have to get a newer book...


Sakari Aaltonen

Re: newbie: Variables in HTML link

am 07.04.2008 13:13:21 von Erwin Moller

Krustov schreef:
>
>
>
>
>
>> I'm reading an introductory book on PHP (circa 2003), where an example
>> contains an HTML link like
>> http://do_something.php?id=55
>>
>> Apparently, this should set the PHP variable $id to a value (here, 55),
>> because do_something.php contains code like
>> >> if(20>$id) {
>> ..........
>> ?>
>>
>> But this never works
>>
>
> > $burp=$_REQUEST['id'];
> if ($burp>20) {print "OK ITS MORE THAN 20
";}
> ?>
>
>
> Or if you want it to be a exact match ....
>
> > $burp=$_REQUEST['id'];
> if ($burp==55) {print "EXACT MATCH FOR 55
";}
> ?>
>
>
> You can also use something like this if wanted .....
>
> > $burp=$_REQUEST['id'];
> if ($burp>0 && <100) {print "TWIN CONDITIONS MATCHED OK
";}
> ?>
>
> This means that $burp needs to be between 1-99 for it to be recognised
> and print "TWIN CONDITIONS MATCHED OK" .
>
>

Hi,

Unless you have a good reason, I advise against using the $_REQUEST[] array.
In my humble opinion using $_REQUEST[] says: "I have no clue where my
data comes from.".

Regards,
Erwin Moller

Re: newbie: Variables in HTML link

am 07.04.2008 15:06:34 von Jerry Stuckle

Erwin Moller wrote:
> Krustov schreef:
>>
>>
>>
>>
>>
>>> I'm reading an introductory book on PHP (circa 2003), where an example
>>> contains an HTML link like
>>> http://do_something.php?id=55
>>>
>>> Apparently, this should set the PHP variable $id to a value (here, 55),
>>> because do_something.php contains code like
>>> >>> if(20>$id) {
>>> ..........
>>> ?>
>>>
>>> But this never works
>>>
>>
>> >> $burp=$_REQUEST['id'];
>> if ($burp>20) {print "OK ITS MORE THAN 20
";}
>> ?>
>>
>>
>> Or if you want it to be a exact match ....
>>
>> >> $burp=$_REQUEST['id'];
>> if ($burp==55) {print "EXACT MATCH FOR 55
";}
>> ?>
>>
>>
>> You can also use something like this if wanted .....
>>
>> >> $burp=$_REQUEST['id'];
>> if ($burp>0 && <100) {print "TWIN CONDITIONS MATCHED OK
";}
>> ?>
>>
>> This means that $burp needs to be between 1-99 for it to be recognised
>> and print "TWIN CONDITIONS MATCHED OK" .
>>
>>
>
> Hi,
>
> Unless you have a good reason, I advise against using the $_REQUEST[]
> array.
> In my humble opinion using $_REQUEST[] says: "I have no clue where my
> data comes from.".
>
> Regards,
> Erwin Moller
>

Agreed. IMHO, using $_REQUEST is only *slightly* better than
register_globals being turned on.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: newbie: Variables in HTML link

am 10.04.2008 10:26:56 von Toby A Inkster

Krustov wrote:

> > $burp=$_REQUEST['id'];
> if ($burp>0 && <100) {print "TWIN CONDITIONS MATCHED OK
";}
> ?>
>
> This means that $burp needs to be between 1-99 for it to be recognised
> and print "TWIN CONDITIONS MATCHED OK" .

?id=0.01

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 14 days, 19:46.]

Tagliatelle with Fennel and Asparagus
http://tobyinkster.co.uk/blog/2008/04/06/tagliatelle-fennel- asparagus/