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.

Use $_POSTfieldname[/i]']

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

thank you this was very helpful.

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; ?><br />
You are <?php echo $age; ?>

</body>
</html>
$foo = $_POST["bar"];

With the HTML:

<form action="foobar.php" method="post">
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.