954,135 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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.

sickly_man
Light Poster
42 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

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

<form action="example.php" method="POST">
<input type="text" name="input_value">
<input type="submit" name="submit">

<?php
if (isset($_POST['submit']))
  {
  // Execute this code if the submit button is pressed.
  $formvalue = $_POST['input_value'];
  }
?>

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['<em>name</em>'] .

Puckdropper
Posting Pro
500 posts since Jul 2004
Reputation Points: 23
Solved Threads: 23
 

thank you this was very helpful.

sickly_man
Light Poster
42 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

index.html

<html>
<body>
<form action="page.php" method="post">
<input type="text" name="fname" />
<input type="text" name="age" />
<input type="Submit" name="Submit">
</form>
</body>
</html>


Page.php

<html>
<body>
<?php $name = $_POST["fname"]; ?>
<?php $age = $_POST["age"]; ?> 
Welcome <?php echo $name; ?>
You are <?php echo $age; ?>

</body>
</html>
mkmirza92
Newbie Poster
1 post since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You