text field values to php variable.......

Thread Solved

Join Date: Jun 2007
Posts: 42
Reputation: sickly_man is an unknown quantity at this point 
Solved Threads: 0
sickly_man's Avatar
sickly_man sickly_man is offline Offline
Light Poster

text field values to php variable.......

 
0
  #1
Jun 19th, 2007
This is probably a stupid question, but I am new to this stuff and need some help. I have a form with a text box and a submit button, and I want to pass the user-entered contents of the text box to a php variable ($size) when the user clicks the submit button. how do i do this??? any help is greatly appreciated. i can post my code if you think that will help just ask me.
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 494
Reputation: Puckdropper is an unknown quantity at this point 
Solved Threads: 21
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: text field values to php variable.......

 
0
  #2
Jun 20th, 2007
Use $_POST['fieldname']

You said you're a beginner, so I wrote a very short description on how the whole process works. You may already be familiar with the basics of forms, but if not, read on. Don't be afraid to do Google searches, either. Remember, you're a web developer, your browser should be already RUNNING. (-:

Take this code snippet: (Which is not guaranteed to be error free, it's for example purposes only.)


  1. <form action="example.php" method="POST">
  2. <input type="text" name="input_value">
  3. <input type="submit" name="submit">
  4.  
  5. <?php
  6. if (isset($_POST['submit']))
  7. {
  8. // Execute this code if the submit button is pressed.
  9. $formvalue = $_POST['input_value'];
  10. }
  11. ?>


The first several lines are a simple basic input form. We're passing variables by the POST method, which keeps them from being appended to the URL on submit. (There's also GET)

When the user clicks on "Submit" (or "Submit Query" because I didn't give the button a label), the browser will load the file indicated by action=, which for the sake of this example is the one with the form.

The script will then start executing at the if (isset($_POST['submit'])) line, as the submit button was pressed. To access form values, you'd use $_POST['name'].
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 42
Reputation: sickly_man is an unknown quantity at this point 
Solved Threads: 0
sickly_man's Avatar
sickly_man sickly_man is offline Offline
Light Poster

Re: text field values to php variable.......

 
0
  #3
Jun 20th, 2007
thank you this was very helpful.
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 1
Reputation: mkmirza92 is an unknown quantity at this point 
Solved Threads: 0
mkmirza92 mkmirza92 is offline Offline
Newbie Poster

U May Write this by writing Code in two Files

 
0
  #4
Jun 3rd, 2009
index.html

  1. <html>
  2. <body>
  3. <form action="page.php" method="post">
  4. <input type="text" name="fname" />
  5. <input type="text" name="age" />
  6. <input type="Submit" name="Submit">
  7. </form>
  8. </body>
  9. </html>

Page.php

  1. <html>
  2. <body>
  3. <?php $name = $_POST["fname"]; ?>
  4. <?php $age = $_POST["age"]; ?>
  5. Welcome <?php echo $name; ?><br />
  6. You are <?php echo $age; ?>
  7.  
  8. </body>
  9. </html>
Last edited by peter_budo; Jun 3rd, 2009 at 1:27 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 7003 | Replies: 3
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC