p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: HTML Web Form Problem


Message #1 by "Mark Everhart" <meverha1@h...> on Sun, 14 Apr 2002 21:20:09 -0400
Hi all,

I'm having a problem with PHP running on the following:

IIS on Windows XP Pro.
PHP downloaded and installed as per the Beginning PHP 4 book

I'm starting the examples in Chapter 3, the HTML form ones.  Anyway, I can 
not get PHP to echo the data submitted in my form.

Here is the code of the HTML form.

<HTML>
<HEAD></HEAD>
<BODY>
<FORM METHOD=GET ACTION="text.php">
Who is your favourite author?
<INPUT NAME="Author" TYPE="TEXT">
<BR>
<BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>

Here is the code for the php response file:

<HTML>
<HEAD></HEAD>
<BODY>
Your favorite author is:
<?php
echo $Author;
?>
</BODY>
</HTML>

According to this PHP should echo the data contained in "Author" but it 
isn't.  Does anyone see something that I'm overlooking?  Is it a possible 
problem with my install of PHP?

Thanks,
Mark



_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com

Message #2 by nicolai_thorning@h... on Mon, 15 Apr 2002 11:23:03
Hi.

I can't add anything useful, except to say I have the same problem. I 
even downloaded the code from the site here and it still wont work. Same 
text as you have printed.

Regards,
Nicolai
Message #3 by "svazi" <svaziphil@s...> on Mon, 15 Apr 2002 12:03:03
Hi
I had the same problem. I installed according to the book. I also have XP 
and IIS.

If I put the extension php_gd.dll on comment (;)(which you uncomment 
according to the book) all the php programms work fine, but as soon I try 
to load any extension, all the php files don't work.

It is not a real solution, but at least for now it runs. I do not know 
what is the correct solution.

phil




> Hi all,

I'm having a problem with PHP running on the following:

IIS on Windows XP Pro.
PHP downloaded and installed as per the Beginning PHP 4 book

I'm starting the examples in Chapter 3, the HTML form ones.  Anyway, I 
can 
not get PHP to echo the data submitted in my form.

Here is the code of the HTML form.

<HTML>
<HEAD></HEAD>
<BODY>
<FORM METHOD=GET ACTION="text.php">
Who is your favourite author?
<INPUT NAME="Author" TYPE="TEXT">
<BR>
<BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>

Here is the code for the php response file:

<HTML>
<HEAD></HEAD>
<BODY>
Your favorite author is:
<?php
echo $Author;
?>
</BODY>
</HTML>

According to this PHP should echo the data contained in "Author" but it 
isn't.  Does anyone see something that I'm overlooking?  Is it a possible 
problem with my install of PHP?

Thanks,
Mark



_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com

Message #4 by "Nicolai Thorning" <nicolai_thorning@h...> on Mon, 15 Apr 2002 13:09:42
<?php
echo $Author;
?>

I solved the problem thanks to Nik from another of the boards here. I 
didn't have to change anything in the php.ini file. However, as I am 
using PHP 4.1 there are some comments that it is better to use this 
syntax for GET and so on.

<?php
echo $_GET["Author"];
?>

That'a what I did and now it works.

You can read more in the php.ini file in the first section "About this 
file" - the part with "-register_global = off".

Nicolai
Message #5 by "Nicolai Thorning" <nicolai_thorning@h...> on Tue, 16 Apr 2002 10:53:18
> <?php
> echo $_GET["Author"];
> ?>

Don't do the quotation marks around Author, it will cause problems later 
on. I found out. It works fine without them as well.

Nicolai
Message #6 by "Nikolai Devereaux" <yomama@u...> on Tue, 16 Apr 2002 08:47:59 -0700
> > <?php
> > echo $_GET["Author"];
> > ?>
>
> Don't do the quotation marks around Author, it will cause problems later
> on. I found out. It works fine without them as well.

NOnono, this is correct.  The reason you were having a problem is because
your variable was embedded in a string, and the quote marks around "Author"
would've terminated the string.

The following statements produce the same results:

echo $_GET["Author"];
echo "$_GET[Author]";
echo $_GET['Author'];
echo "{$_GET['Author']}";


The following should produce an error:

echo $_GET[Author];
echo "$_GET['Author']";
echo $_GET["'Author'"];
echo "{$_GET[Author]}";


nik

Message #7 by "Nicolai Thorning" <nicolai_thorning@h...> on Tue, 16 Apr 2002 18:07:33
Quote:
NOnono

Hehe, thanks Nik - and here I thought I had it all figured out. :D

Why is it then that it works ok in the above example (without the marks), 
but not for insance in the other example I posted with checkboxes? Is 
that because the other was a string and this is ...

I am getting confused.

Thanks.
Nicolai
Message #8 by "Nicolai Thorning" <nicolai_thorning@h...> on Tue, 16 Apr 2002 18:10:48
Sorry for all the posts, but would that be because of the <br> I enter in 
the checkbox example?

echo $_GET['Choice1'] . '<br>' //good

echo $_GET[Chocice1]<br> //bad

Is that it?

Nicolai

Message #9 by "Nikolai Devereaux" <yomama@u...> on Tue, 16 Apr 2002 10:10:52 -0700
> Sorry for all the posts, but would that be because of the <br> I enter in
> the checkbox example?
>
> echo $_GET['Choice1'] . '<br>' //good
>
> echo $_GET[Chocice1]<br> //bad
>
> Is that it?

Well, the string "Choice1" (or 'Choice1', they're the same) is the index
into the $_GET array.

The first one is good because 'Choice1' is a string, and '<br>' is a string.

The second one is wrong in BOTH accounts.



CORRECT:
echo $_GET['Choice1'] . '<br>';

INCORRECT:
echo $_GET['Choice1'] .  <br>;
echo $_GET[Choice1]   . '<br>';
echo $_GET[Choice1]   .  <br>;


take care,

nik

Message #10 by "Nicolai Thorning" <nicolai_thorning@h...> on Tue, 16 Apr 2002 18:43:15
Thanks.

It is just because you said this should produce an error:

echo $_GET[Author];

which it doesn't (at least not in the example I have on my pc) - so I 
thought it had to do with something else.

I'll leave it anyway, and come back if I run across something later on.

Thanks again.
Nicolai

  Return to Index