|
|
 |
| Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning PHP section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

November 22nd, 2005, 05:42 PM
|
|
Registered User
|
|
Join Date: Nov 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Passing variables
I can't get the variable to pass to php in the following
-----------------------
in kform.htm I have (this form works ok)
<HTML>
<HEAD>
First Form
<?HEAD>
<BODY>
<FORM METHOD="POST" ACTION="kform1.php">
<P> First Name: <INPUT TYPE = "text" Name = "firstname SIZE = "20">
<P><P>
<INPUT TYPE="submit" VALUE="Send info">
<INPUT TYPE="reset">
</FORM>
</BODY>
</HTML>
------------------------------
in kform1.php , I have
<?php
$firstname = $_GET['firstname'];
echo "Hi, your first name is: $firstname" ;
?>
---------------------------
When I run this I get
Notice: Undefined index: firstname in C:\Program Files\BadBlue\PE\kform1.php on line 4
Hi, your first name is:
|

November 23rd, 2005, 06:52 AM
|
|
Authorized User
|
|
Join Date: Oct 2003
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
If your method of sending the form is POST, the way to access the variable is $_POST['firstname'] not $_GET['firstname']
try:
<?php
$firstname = $_POST['firstname'];
echo "Hi, your first name is: $firstname" ;
?>
Or you could argue why even create another variable ($firstname) use:
<?php
echo "Hi, your first name is: $_POST[firstname]" ;
?>
>>>>note the missing '' around $firstname because the variable is encased in double quotes
HTH
David
|

December 2nd, 2005, 11:25 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Location: South San Francisco, CA, USA.
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try this:
a) on form kform.htm add an attribute NAME="submit" after input TYPE="submit" have a space in between.
b) on <INPUT TYPE="text" add the " after firstname:
NAME="firstname" SIZE="20">
c) on form kform1.php:
<?php
$firstname = $_POST['firstname'];
// This means if submit button is not click.
if( !array_key_exits('submit', $_POST) || empty($firstname) )
{
print <<<_HERE;
<FORM METHOD="POST" ACTION="kform1.php">
<P>First Name: <INPUT TYPE="text" NAME="firstname" SIZE="20">
</P> <P />
<INPUT TYPE="submit" NAME="submit" VALUE="Send info">
<INPUT TYPE="reset">
</FORM>
_HERE;
}
else
{
echo "Hi, your first name is: $firstname";
}
?>
Note: the word _HERE; should be at the leftmost side of your code to work.
Hope this helps.
John M.
|

December 9th, 2005, 04:37 PM
|
|
Registered User
|
|
Join Date: Dec 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yes, use the array $_POST instead of $_GET, so it's $_POST[firstname] instead of $_GET[firstname]
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Passing Variables |
silve1999 |
Pro Java |
1 |
June 15th, 2006 01:54 PM |
| Passing Variables |
CMOS |
Classic ASP Basics |
2 |
January 22nd, 2006 07:38 PM |
| Passing variables |
karlirvin |
PHP How-To |
4 |
December 2nd, 2005 08:02 PM |
| passing variables. |
ashokparchuri |
ASP.NET 1.1 |
4 |
March 18th, 2005 05:36 AM |
| Passing variables |
acko |
ASP.NET 1.x and 2.0 Application Design |
1 |
December 23rd, 2003 09:40 AM |
|
 |