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