0

I jut recently started learning PHP from a book called PHP/MySQL Programming for the Absolute Beginner by Andy Harris.

In one of his samples, he writes that this code should function (I've cut it short a bit):

<html>
<head>
<title>Font Choices</title>
</head>
<body>
<center>
<h1>Font Choices</h1>
<h3>Demonstrates how to read HTML form elements</h3>

<form method = "post"
      action = "borderMaker.php">


<h3>Text to modify</h3>
<textarea name = "basicText"
      rows = "10"
      cols = "40">
blah blah
</textarea>



<input type = "submit"
       value = "show me">

</form>

</center>
</body>
</html>

Then in Bordermaker.php something like:

<html>
<head>
<title>Your Output</title>
</head>
<body>
<h1>Your Output</h1>
<center>
<?


print $basicText;

?>
</center>

</body>
</html>

But when i try to run it it says I can't find the $basicText variable.

I'm currently learning PHP with XAMPP running on my computer.

Thanks for any help.

1
  • When you hit the submit button from your forms page, are the variables being sent in the url string when it tries to transfer pages? Commented Apr 8, 2011 at 18:39

2 Answers 2

4

use $_POST['basicText'] instead of $basicText

You are using the "post" method on your form so all your input values will be contained in an array called $_POST.

If you were using "get" as your method, all the form information would be passed as a query string on the end of your url, and you would access them with an array called $_GET the same way.

Sign up to request clarification or add additional context in comments.

1 Comment

@Kevin You should make his answer as correct if it helped you out :)
1

This example relies on the usage of register_globals to function. What this means is that every variable submitted via form becomes a global variable, which means random-joe can inject unknown variables into your code. This has been deprecated as of 5.3 and will be removed in later versions.

I highly recommend finding a book based on later versions of PHP to learn from, preferably something tailored to PHP 5 (at minimum).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.