By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

passing variables between pages

P: n/a
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");
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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
Jul 17 '05 #2

P: n/a
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)) {

Jul 17 '05 #3

P: n/a
Matthew Robinson <ma*************@hotmail.com> schrieb:
<form action="<?php $PHP_SELF ?>" method="GET"> <table>
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>
</td>
</form>
</div>


You forgot to close the table row and the table.

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

Regards,
Matthias
Jul 17 '05 #4

P: n/a
Matthew Robinson wrote:
search.php?search=&catagory=Search+All+Catagories

if (empty($catagory)) {


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 =--
Jul 17 '05 #5

P: n/a
thanks again pedro - i am gonna read the manual now (the link you gave me)
Jul 17 '05 #6

P: n/a
Matthew Robinson <ma*************@hotmail.com> schrieb:
search.php?search=&catagory=Search+All+Catagories

if statement:

if (empty($catagory)) {


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

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

Regards,
Matthias
Jul 17 '05 #7

P: n/a
On Thu, 08 Jan 2004 23:34:32 +0000, Matthew Robinson wrote:
i read a tutorial the other day on passing variables between php pages


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|
-------------------------

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.