Simple script issue?
for some reason I cannot get any form to work correctly on my website, I even went to w3school and copied a simple test form to see if it works, and it does not, here it is:
welcome.php:
<? Welcome <?php echo $_GET["fname"]; ?>!<br /> You are <?php echo $_GET["age"]; ?> years old. ?>
form:
<form action="welcome.php" method="get"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form>
I'm not sure if it matters or not, but I tried with and without brackets, and still I get a blank page, in explorer I get a 500 Error, most likely causes is maintenance or Programming Error", but I had the same issue last night so I doubt its maintenance, and ev开发者_如何学Cerything else works.
Remove the beginning <?
and ending ?>
from your welcome.php.
Your form uses get
and you're reading from $_POST
.
Either change html to
<form action="welcome.php" method="post">
or change the php to
Welcome <?php echo $_GET["fname"]; ?>!<br />
You are <?php echo $_GET["age"]; ?> years old.
Also, make sure the value is present using the isset
Welcome <?php echo isset($_GET["fname"]) ? $_GET["fname"] : "Guest"; ?>!<br />
When you use $_POST["fname"]
you should also specify post as method in your form
welcome.php:
<?
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
?>
form:
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
精彩评论