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

variable not set..

P: n/a
Hello!

I'm making my first PHP page and got stuck already. Its going to be a
guestbook.

My code:

<HTML><HEAD><TITLE>My
guestbook</TITLE></HEAD><BODY><H1>Welcome</H1><H2>
Write something:</H2><form action="<?echo $PHP_SELF?>" method="POST">
<textarea cols=40 rows=5 name=note wrap=virtual></textarea><input
type=submit value="Send"></form>

<?

if(isset($note)) This is as far as I get - $note is NOT set when I
get here, why?

..... etc.

The rest of the code seems to work, if I hardcode $note = "bla" the
guestbook saves it and shows it next time etc.

Greatful for quick help!
/CV
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Camilla wrote:
Hello!

I'm making my first PHP page and got stuck already. Its going to be a
guestbook.

My code:

<HTML><HEAD><TITLE>My
guestbook</TITLE></HEAD><BODY><H1>Welcome</H1><H2>
Write something:</H2><form action="<?echo $PHP_SELF?>" method="POST">
<textarea cols=40 rows=5 name=note wrap=virtual></textarea><input
type=submit value="Send"></form>

<?

if(isset($note)) This is as far as I get - $note is NOT set when I
get here, why?


Register_globals is set to OFF by default now. See
http://www.php.net/register_globals for more information. Reference
your variable via $_POST['note']

Ken

Jul 17 '05 #2

P: n/a
Camilla wrote:

<HTML><HEAD><TITLE>My
guestbook</TITLE></HEAD><BODY><H1>Welcome</H1><H2>
Write something:</H2><form action="<?echo $PHP_SELF?>" method="POST">
<textarea cols=40 rows=5 name=note wrap=virtual></textarea><input
type=submit value="Send"></form>

<?

if(isset($note)) This is as far as I get - $note is NOT set when I
get here, why?

.... etc.

The rest of the code seems to work, if I hardcode $note = "bla" the
guestbook saves it and shows it next time etc.


It'll only be set WHEN the form is POSTED and IF register_globals is set
(which it shouldn't be). Try reading from $_REQUEST['note'] instead.

HTH

C.
Jul 17 '05 #3

P: n/a
Try putting
action="<?php $_SERVER['PHP_SELF']; ?>"
in the form attributes rather than
action="<?echo $PHP_SELF?>"
Then
$note = $_POST['note']
to retrieve the $note variable

Jul 17 '05 #4

P: n/a
Thanks a lot, all of you!
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.