Forums

PHP

This topic is locked

if...elseif...else

Posted 11 Dec 2011 18:47:58
1
has voted
11 Dec 2011 18:47:58 Laurentiu Burcu posted:
I've tried to do something and I've got this message:
"Undefined index: sentence2 in C:\wamp\www\newtest\I_have_just.php on line 18"

the PHP scipt is:
<head>
<title> I have just - php-listing 9.2</title>
</head>
<body>

<?php

$txt="I have just written a book.";
$txt1="I just wrote a book.";
$txt2="I wrote a book.";

if ($txt=="I have just written a book!") {
   echo " You chose [b]$_POST[sentence][/b]<br />";
} else if ($txt1=="I just wrote a book!") {
   echo " You chose [b]$_POST[sentence1][/b]<br />";
} else { 
   echo " You chose [b]$_POST[sentence2][/b]<br />";
}


//echo "[h2]You may go on[/h2]";

// echo "<p>I have just written a book![br] You chose [b]$_POST[sentence][/b]</p>";
// echo "<p>I just wrote a book![br] You chose [b]$_POST[sentence1][/b]</p>";
// echo "<p>I wrote a book![br] You chose [b]$_POST[sentence2][/b]</p>";

echo "<br />";
echo "<br />";
?>
<a href="http://localhost/newtest/I_have_just.htm">Back</a>

</body>
</html>

AND THE HTM SCRIPT IS:

<html>
<head>
<title>listing 9.1 html</title>
</head>
<body>
<form action="I_have_just.php" method="POST">

<p>[b]Choose the correct one:[/b]</p>

<p>I have just written a book.<br />
<input type="checkbox" name="sentence" value="corect!"></p>

<p>I just wrote a book.<br />
<input type="checkbox" name="sentence1" value="gresit!"></p>

<p>I wrote a book.<br />
<input type="checkbox" name="sentence2" value="gresit!"></p>

<p><input type="submit" value="see the result"></p>

</form>
</body>
</html>

Replies

Replied 20 Dec 2011 14:53:55
20 Dec 2011 14:53:55 Patrick Woldberg replied:
you forgot the quotes

$_POST[sentence2] -> $_POST['sentence2']

Reply to this topic