Home > Archive > PHP Language > March 2004 > trouble passing variable to new page
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
trouble passing variable to new page
|
|
|
| I am a newbie following Tim Ziegler's forms lesson on
http://hotwired.lycos.com/webmonkey...?tw=programming
I have copied the code directly from the page, but when tried the
example I get only the hard coded text without the variables. I
changed the form action from post to get and I can then see the values
in the URL of the PHP page, but they still don't appear on the page
body. I tried simplifying the page so that all it did was print out
one of the variables. I then got nothing in the page body. I tried to
define and print the same variables on a different page using PHP and
that works fine. Any ideas what I am missing?
| |
| Andrew C. 2004-03-28, 10:10 pm |
|
"Alan" <please@thanks.com> wrote in message
news:O8r9c.20278$Xd1.14414@twister.socal.rr.com...
> I am a newbie following Tim Ziegler's forms lesson on
>
>
http://hotwired.lycos.com/webmonkey...?tw=programming
>
> I have copied the code directly from the page, but when tried the
> example I get only the hard coded text without the variables. I
> changed the form action from post to get and I can then see the values
> in the URL of the PHP page, but they still don't appear on the page
> body. I tried simplifying the page so that all it did was print out
> one of the variables. I then got nothing in the page body. I tried to
> define and print the same variables on a different page using PHP and
> that works fine. Any ideas what I am missing?
I am something of a PHP newbie myself, but I think I can make a suggestion
on this one.
It all hinges on one crucial question: When you browse to
'badwords_form.html', do you do so by simply double-clicking it on your
local computer like you would to try out any other '.html' file?
If the answer is to this is 'yes', that will almost certainly be your
problem.
To use PHP, you need something involved that understands PHP -- and a
browser won't do it. PHP is a server-side scripting language and requires a
suitable web server (such as apache with the PHP module installed) to run
the PHP for you. (This is a different situation than JavaScript, for
example, which is a client-side scripting language, and therefore is dealt
with by the client, i.e. the browser itself).
I won't waffle on any more just in case the answer to the crucial question
was 'no'! :)
.... But if it was 'yes', then there's almost certainly nothing wrong with
your understanding of PHP -- just the environment that it needs to operate
in.
A.
| |
|
| Thanks for responding but actually I have installed an apache server, PHP,
and MySQL. The files are published to that apache server.
I have figured out a work around to the problem. I have discovered that if
instead of trying to print $YourName as the example shows, I instead print
$_POST['YourName'} that I am successful. I just wish that I understood why I
am not able to print the way that the example shows.
I have the same problem when trying to insert data into MySQL tables. I
first have to use the $_POST['variable'] to grab the value from the POST,
then stick its value into another variable before inserting into the table.
Again, the example in a tutorial doesn't do it that way.
"Andrew C." <backwards.moc.senrocwerdna@swenaret.backwards> wrote in message
news:5c03848d7d2efe3187cef064dbb0480b@ne
ws.teranews.com...
>
> "Alan" <please@thanks.com> wrote in message
> news:O8r9c.20278$Xd1.14414@twister.socal.rr.com...
>
http://hotwired.lycos.com/webmonkey...?tw=programming
>
> I am something of a PHP newbie myself, but I think I can make a suggestion
> on this one.
>
> It all hinges on one crucial question: When you browse to
> 'badwords_form.html', do you do so by simply double-clicking it on your
> local computer like you would to try out any other '.html' file?
>
> If the answer is to this is 'yes', that will almost certainly be your
> problem.
>
> To use PHP, you need something involved that understands PHP -- and a
> browser won't do it. PHP is a server-side scripting language and requires
a
> suitable web server (such as apache with the PHP module installed) to run
> the PHP for you. (This is a different situation than JavaScript, for
> example, which is a client-side scripting language, and therefore is dealt
> with by the client, i.e. the browser itself).
>
> I won't waffle on any more just in case the answer to the crucial question
> was 'no'! :)
>
> ... But if it was 'yes', then there's almost certainly nothing wrong with
> your understanding of PHP -- just the environment that it needs to operate
> in.
>
> A.
>
>
| |
|
| On Mon, 29 Mar 2004 08:53:06 +0000, Alan wrote:
Please don't top post.. it messes up the natural flow of reading and makes
threads harder to read for people that haven't followed the read from
the start (and indeed those that have).
<http://tk.digiserv.net/tofu.txt>
> Thanks for responding but actually I have installed an apache server, PHP,
> and MySQL. The files are published to that apache server.
>
> I have figured out a work around to the problem. I have discovered that if
> instead of trying to print $YourName as the example shows, I instead print
> $_POST['YourName'} that I am successful. I just wish that I understood why I
> am not able to print the way that the example shows.
>
> I have the same problem when trying to insert data into MySQL tables. I
> first have to use the $_POST['variable'] to grab the value from the POST,
> then stick its value into another variable before inserting into the table.
> Again, the example in a tutorial doesn't do it that way.
This is for security reasons.. short and simple =)
Picture this as a crude example:
Your script requires login credentials which are then handled by SESSIONs
for access. Your login form uses the POST method. With your method.. using
a URL such as:
http://foo.com/?user=foo&pass=bar
would suffice and satisfy your criteria... but this is a GET request and
surely not how you intended your site to be accessed.
For this reason, since PHP4.2.0 the default was to disable
'register_globals' (the setting that controls this handling) and we now
have 'SuperGlobals':
$_GET[]
$_POST[]
$_SESSION[]
$_COOKIE[]
$_SERVER[]
$_FILES[]
etc etc. This means that if the data _MUST_ come from your expected
method.. this increasing security a little (obviously this matters not if
the rest of your code is as secure as the likes of Redmond code).
For a more indepth explanation, see <http://php.net/> and do a search for
'register_globals' and read the info about security.. it should clear up
any confusion remaining =)
HTH.
Regards,
Ian
--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
|
|
|
|
|