943,747 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 21397
  • PHP RSS
Jun 19th, 2007
0

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

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
sickly_man is offline Offline
42 posts
since Jun 2007
Jun 20th, 2007
0

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

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.)


PHP Syntax (Toggle Plain Text)
  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'].
Reputation Points: 23
Solved Threads: 23
Posting Pro in Training
Puckdropper is offline Offline
494 posts
since Jul 2004
Jun 20th, 2007
0

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

thank you this was very helpful.
Reputation Points: 10
Solved Threads: 0
Light Poster
sickly_man is offline Offline
42 posts
since Jun 2007
Jun 3rd, 2009
0

U May Write this by writing Code in two Files

index.html

html Syntax (Toggle Plain Text)
  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

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mkmirza92 is offline Offline
1 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: zipcodes packages
Next Thread in PHP Forum Timeline: how to create a link in a view page:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC