Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

Use of assignment to $[ is deprecated at /usr/local/sbin/apxs line 86. , wwwxxx vim, mysql closing table and opening table, 800c5000, setgid operation not permitted, pciehp: acpi_pciehprm on IBM, WWWXXX.DBF, 078274121, info0a ip, should prodicers of software_based services be held liable or not liable for economic injuries

Links

XODOX
Impressum

#1: newbie: Variables in HTML link

Posted on 2008-04-07 11:19:28 by 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
<?php
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!

Report this message

#2: Re: newbie: Variables in HTML link

Posted on 2008-04-07 11:46:02 by 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
> <?php
> 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

Report this message

#3: Re: newbie: Variables in HTML link

Posted on 2008-04-07 11:48:07 by 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
> <?php
> 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.

Report this message

#4: Re: newbie: Variables in HTML link

Posted on 2008-04-07 11:51:47 by 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
> <?php
> 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

Report this message

#5: Re: newbie: Variables in HTML link

Posted on 2008-04-07 12:31:38 by Hans-Peter Sauer

<comp.lang.php>
<Sakari Aaltonen>
<Mon, 7 Apr 2008 12:19:28 +0300 (EEST)>
<ftcov0$8pq$1@epityr.hut.fi>

> 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
> <?php
> if(20>$id) {
> ..........
> ?>
>
> But this never works
>

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


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

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


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

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

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

Report this message

#6: Re: newbie: Variables in HTML link

Posted on 2008-04-07 13:05:31 by Sakari Aaltonen

In article <47f9ed56$0$14350$e4fe514c@news.xs4all.nl>,
Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> 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

Report this message

#7: Re: newbie: Variables in HTML link

Posted on 2008-04-07 13:13:21 by Erwin Moller

Krustov schreef:
> <comp.lang.php>
> <Sakari Aaltonen>
> <Mon, 7 Apr 2008 12:19:28 +0300 (EEST)>
> <ftcov0$8pq$1@epityr.hut.fi>
>
>> 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
>> <?php
>> if(20>$id) {
>> ..........
>> ?>
>>
>> But this never works
>>
>
> <?php
> $burp=$_REQUEST['id'];
> if ($burp>20) {print "OK ITS MORE THAN 20<br>";}
> ?>
>
>
> Or if you want it to be a exact match ....
>
> <?php
> $burp=$_REQUEST['id'];
> if ($burp==55) {print "EXACT MATCH FOR 55 <br>";}
> ?>
>
>
> You can also use something like this if wanted .....
>
> <?php
> $burp=$_REQUEST['id'];
> if ($burp>0 && <100) {print "TWIN CONDITIONS MATCHED OK <br>";}
> ?>
>
> 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

Report this message

#8: Re: newbie: Variables in HTML link

Posted on 2008-04-07 15:06:34 by Jerry Stuckle

Erwin Moller wrote:
> Krustov schreef:
>> <comp.lang.php>
>> <Sakari Aaltonen>
>> <Mon, 7 Apr 2008 12:19:28 +0300 (EEST)>
>> <ftcov0$8pq$1@epityr.hut.fi>
>>
>>> 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
>>> <?php
>>> if(20>$id) {
>>> ..........
>>> ?>
>>>
>>> But this never works
>>>
>>
>> <?php
>> $burp=$_REQUEST['id'];
>> if ($burp>20) {print "OK ITS MORE THAN 20<br>";}
>> ?>
>>
>>
>> Or if you want it to be a exact match ....
>>
>> <?php
>> $burp=$_REQUEST['id'];
>> if ($burp==55) {print "EXACT MATCH FOR 55 <br>";}
>> ?>
>>
>>
>> You can also use something like this if wanted .....
>>
>> <?php
>> $burp=$_REQUEST['id'];
>> if ($burp>0 && <100) {print "TWIN CONDITIONS MATCHED OK <br>";}
>> ?>
>>
>> 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
==================

Report this message

#9: Re: newbie: Variables in HTML link

Posted on 2008-04-10 10:26:56 by Toby A Inkster

Krustov wrote:

> <?php
> $burp=$_REQUEST['id'];
> if ($burp>0 && <100) {print "TWIN CONDITIONS MATCHED OK <br>";}
> ?>
>
> 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/

Report this message