p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > PHP/MySQL > Beginning PHP
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 22nd, 2005, 05:42 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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:


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 23rd, 2005, 06:52 AM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old December 2nd, 2005, 11:25 PM
Friend of Wrox
Points: 281, Level: 5
Points: 281, Level: 5 Points: 281, Level: 5 Points: 281, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: South San Francisco, CA, USA.
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old December 9th, 2005, 04:37 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, use the array $_POST instead of $_GET, so it's $_POST[firstname] instead of $_GET[firstname]

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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



All times are GMT -4. The time now is 08:14 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc