p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: passing a variable through more than one form - newbie


Message #1 by "David Sharpington" <gatton@c...> on Sat, 1 Feb 2003 16:22:04
Hi

I'm just working my way through pages 71 onwards of the Beginning PHP book.

I've submitted a a query and it picked it up as php variable - $Author - 
just fine. What I would like to do, though, is have another form on that 
same page and then carry both that input and the $Author to a third page.

I can't get it to pick up the first query value, though. I've tried this:

<HTML>
<BODY>

Your favourite author is:
<?php echo $Author; ?> 

<form method="get" action="ftest4.php">
Who is your favourite singer?
<input type="hidden" name="Author" value=$Author>
<input name="Singer" type="text">
<br>
<br>
<input type="submit">
</form>
</BODY>
</HTML>

When I submit this, I get the value of Singer, but SAuthor instead of the 
value. Any advice, please?

Thanks

Dave S

PS the reason I'm doing this is I am trying to construct a questionnaire & 
don't want too many questions on one page.
Message #2 by "Nikolai Devereaux" <yomama@u...> on Sat, 1 Feb 2003 10:11:51 -0800
You're running into the most popular problem on the list -- register_globals
is Off by default in recent versions of PHP, but when the book was written it
was On.

For more info, read the manual at
  http://www.php.net/security.registerglobals

and a FAQ type post I made a couple months back:
  http://p2p.wrox.com/archive/beginning_php/2002-11/17.asp

Also, there are literally hundreds of posts about people having problems with
register_globals.  Any web search (including one on the p2p list archives) for
"register_globals" should lead you to several hits.


Take care,

Nik

Message #3 by "David Sharpington" <gatton@c...> on Sat, 1 Feb 2003 19:13:39
> 
You're running into the most popular problem on the list -- 
register_globals
is Off by default in recent versions of PHP, but when the book was written 
it
was On.

For more info, read the manual at
  http://www.php.net/security.registerglobals

and a FAQ type post I made a couple months back:
  http://p2p.wrox.com/archive/beginning_php/2002-11/17.asp

Also, there are literally hundreds of posts about people having problems 
with
register_globals.  Any web search (including one on the p2p list archives) 
for
"register_globals" should lead you to several hits.


Take care,

Nik

Message #4 by "David Sharpington" <gatton@c...> on Sat, 1 Feb 2003 19:15:31
Thank you very much for the advice

Regards

Dave S


You're running into the most popular problem on the list -- 
register_globals
is Off by default in recent versions of PHP, but when the book was written 
it
was On.

For more info, read the manual at
  http://www.php.net/security.registerglobals

and a FAQ type post I made a couple months back:
  http://p2p.wrox.com/archive/beginning_php/2002-11/17.asp

Also, there are literally hundreds of posts about people having problems 
with
register_globals.  Any web search (including one on the p2p list archives) 
for
"register_globals" should lead you to several hits.


Take care,

Nik

Message #5 by "Chris Koncewicz" <koncewicz@b...> on Sat, 1 Feb 2003 19:43:52 -0000
Maybe register globals would have something to do with it, but isn't 
this
problem caused by the fact that $Author has been typed in an HTML 
region? It
needs <?php and ?> around it, and should read 'echo $Author;'
Or echo '$_POST['Author'];' depending on whether register globals is on 
or
off.

-----Original Message-----
From: David Sharpington [mailto:gatton@c...]
Sent: 01 February 2003 16:22
To: beginning php
Subject: [beginning_php] passing a variable through more than one form -
newbie

Hi

I'm just working my way through pages 71 onwards of the Beginning PHP 
book.

I've submitted a a query and it picked it up as php variable - $Author - 

just fine. What I would like to do, though, is have another form on that 

same page and then carry both that input and the $Author to a third 
page.

I can't get it to pick up the first query value, though. I've tried 
this:

<HTML>
<BODY>

Your favourite author is:
<?php echo $Author; ?>

<form method=3D"get" action=3D"ftest4.php">
Who is your favourite singer?
<input type=3D"hidden" name=3D"Author" value=3D$Author>
<input name=3D"Singer" type=3D"text">
<br>
<br>
<input type=3D"submit">
</form>
</BODY>
</HTML>

When I submit this, I get the value of Singer, but SAuthor instead of 
the
value. Any advice, please?

Thanks

Dave S

PS the reason I'm doing this is I am trying to construct a questionnaire 
&
don't want too many questions on one page.


Message #6 by "David Sharpington" <gatton@c...> on Sat, 1 Feb 2003 22:33:14
Thank you for this, you are right, now I'm almost there but not quite. 
After a few combinations the best I have is:

<input type="hidden" name="Author" value=<?php echo $Author; ?>>

This will pass on the value but for some reason not all of it , eg if 
Joseph+Keller is passed from the previous form then the code above passes 
on the 'Joseph' but not the 'Keller'.

Regards

Dave S


> Maybe register globals would have something to do with it, but isn't 
this
problem caused by the fact that $Author has been typed in an HTML 
region? It
needs <?php and ?> around it, and should read 'echo $Author;'
Or echo '$_POST['Author'];' depending on whether register globals is on 
or
off.

-----Original Message-----
From: David Sharpington [mailto:gatton@c...]
Sent: 01 February 2003 16:22
To: beginning php
Subject: [beginning_php] passing a variable through more than one form -
newbie

Hi

I'm just working my way through pages 71 onwards of the Beginning PHP 
book.

I've submitted a a query and it picked it up as php variable - $Author - 

just fine. What I would like to do, though, is have another form on that 

same page and then carry both that input and the $Author to a third 
page.

I can't get it to pick up the first query value, though. I've tried 
this:

<HTML>
<BODY>

Your favourite author is:
<?php echo $Author; ?>

<form method=3D"get" action=3D"ftest4.php">
Who is your favourite singer?
<input type=3D"hidden" name=3D"Author" value=3D$Author>
<input name=3D"Singer" type=3D"text">
<br>
<br>
<input type=3D"submit">
</form>
</BODY>
</HTML>

When I submit this, I get the value of Singer, but SAuthor instead of 
the
value. Any advice, please?

Thanks

Dave S

PS the reason I'm doing this is I am trying to construct a questionnaire 
&
don't want too many questions on one page.


Message #7 by "Nikolai Devereaux" <yomama@u...> on Mon, 3 Feb 2003 10:48:43 -0800
> Thank you for this, you are right, now I'm almost there but not quite.
> After a few combinations the best I have is:
>
> <input type="hidden" name="Author" value=<?php echo $Author; ?>>
>
> This will pass on the value but for some reason not all of it , eg if
> Joseph+Keller is passed from the previous form then the code above passes
> on the 'Joseph' but not the 'Keller'.


This makes sense, though.  You're not quoting your attribute value, so the
browser only sends the first token as the input value.

More detailed version:  Your input tag looks like this:

<input type="hidden" name="Author" value=Joseph Keller>


The "Keller" in the above tag is parsed as an attribute with no value assigned
to it, just like the "multiple" in <select multiple>.

You need to change your code from:

  value=<?php echo $Author; ?>

to:

  value="<?php echo $Author; ?>"


Take care,

Nik


  Return to Index