tags:

views:

91

answers:

2
+1  Q: 

Form isn't shown

HI,

I have a file test.php with the following code:

<html>
<head>
<title>Listing 10.2 </title>
</head>
<body>
<div>

<form method="post" action="test.php" >
 <p> <input type="text" name="guess"/> </p>
</form>

<?php
if(!empty($_POST['guess'] )) {
 print "Last guess $_POST['guess']";
}
?>

</div>

</body>
</html>

I have a problem with the form- it simply doens't shows up. However, if I remove the php code it's shown. Where's the problem?

Thanks.

+1  A: 

You can't embed the $_POST variable into the string like that, trying changing the php section to:

<?php
if(!empty($_POST['guess'] )) {
    print "Last guess {$_POST['guess']}";
}
?>
Chad Birch
A: 

Thanks, it works. Why is $_POST a special case? If i put in some random variable it will be printed out normally.

Daniel
See here http://us2.php.net/types.string#language.types.string.parsing
tj111
Specifically, it's not the $_POST that causes the problem, it's the associative array. The square bracket is not a valid character to be used in a variable name, so the simple string parsing stops at that point. You have to use the "complex" syntax for embedding arrays in strings.
Chad Birch
One thing you should also look at is your PHP error-reporting settings. Your problem isn't that the form wasn't being displayed, but that the page was crashing due to a PHP syntax error. You should make sure that you have some way to view those errors, or you'll have a very hard time debugging.
Chad Birch
I get it now. Thanks. How do I set up the error reporting? I allready have error_reporting= E_ALL set in php.ini file, but it doesn't shows these kind of errors.
Daniel