Connecting Tech Pros Worldwide Forums | Help | Site Map

passing variables between pages

Matthew Robinson
Guest
 
Posts: n/a
#1: Jul 17 '05
i read a tutorial the other day on passing variables between php pages
using a html form and setting the action to the php page to parse, can
anybody see anything wrong with the code below? the problem is, that the
page always loads the html form, and i cant work out why this is so, even
after i select a catagory from the drop down list and press search. any1
have any idea's? TIA.

the code:

if (empty($catagory)) { ?>
<div align=center>
<form action="<?php $PHP_SELF ?>" method="GET"> <table>
<tr> <td>
<INPUT name=search>
</td> <td>
<SELECT NAME=catagory SIZE=1>
<OPTION any>Search All Catagories
<OPTION floral>Floral Creations
<OPTION lighting>Decorative Lighting
<OPTION kitchenware>Kitchenware & Crockery <OPTION
furniture>Fancy Goods & Furniture
</SELECT>
</td> <td>
<INPUT TYPE=submit VALUE="Search">
</td>
</form>
</div>
<?php exit; }
echo ("the catagory variable was set");

Matthew Robinson
Guest
 
Posts: n/a
#2: Jul 17 '05

re: passing variables between pages


just thought i would add, that i cant remember the url of the tutorial,
and the notes i took didn't include that part for some unknown reason
Matthew Robinson
Guest
 
Posts: n/a
#3: Jul 17 '05

re: passing variables between pages


just thought of checking the url - thats right, so the problem must be in
my if statement:

end of url:
search.php?search=&catagory=Search+All+Catagories

if statement:

if (empty($catagory)) {

Matthias Esken
Guest
 
Posts: n/a
#4: Jul 17 '05

re: passing variables between pages


Matthew Robinson <mattyrobinson69@hotmail.com> schrieb:
[color=blue]
> <form action="<?php $PHP_SELF ?>" method="GET"> <table>[/color]

Set your error_reporting to E_ALL, so that PHP will inform you of any
errors. Then have a look at the resulting source code of the HTML page
and you should find your error pretty fast. You use $PHP_SELF as a
function, but what you really want is the value of this variable.
Additionally I'd suggest that you use $_SERVER['PHP_SELF']. $_PHP_SELF
will not exist if register_globals is off (which is default since PHP
4.2.0). So your code should be:

<form action="<?php echo($SERVER['PHP_SELF'] ?>" method="GET"> <table>
[color=blue]
> </td>
> </form>
> </div>[/color]

You forgot to close the table row and the table.

00:53AM in Germany. I'm going to bed now. :-)

Regards,
Matthias
Pedro Graca
Guest
 
Posts: n/a
#5: Jul 17 '05

re: passing variables between pages


Matthew Robinson wrote:[color=blue]
> search.php?search=&catagory=Search+All+Catagories
>
> if (empty($catagory)) {[/color]

Read this, _all_ of this

http://www.php.net/manual/en/languag...s.external.php


and follow a few of the links there, too




a (the usual?) way to do what you want is

if (empty($_GET['catagory'])) {


but do not bypass reading the manual :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Matthew Robinson
Guest
 
Posts: n/a
#6: Jul 17 '05

re: passing variables between pages


thanks again pedro - i am gonna read the manual now (the link you gave me)
Matthias Esken
Guest
 
Posts: n/a
#7: Jul 17 '05

re: passing variables between pages


Matthew Robinson <mattyrobinson69@hotmail.com> schrieb:
[color=blue]
> search.php?search=&catagory=Search+All+Catagories
>
> if statement:
>
> if (empty($catagory)) {[/color]

if (isset($_GET['catagory'])) {

And you might want to change "catagory" to "category". :-)

Regards,
Matthias
Jeffrey Silverman
Guest
 
Posts: n/a
#8: Jul 17 '05

re: passing variables between pages


On Thu, 08 Jan 2004 23:34:32 +0000, Matthew Robinson wrote:
[color=blue]
> i read a tutorial the other day on passing variables between php pages[/color]

A lot of on-the-web php tutorials (webmonkey, for example) have gotten out
of date.

Look up register_globals()!

--
-------------------------
| Jeffrey Silverman |
| jeffrey-AT-jhu-DOT-edu|
-------------------------

Closed Thread