Posted by ED on 07/10/07 08:27
"Dan Oakes" <Dan.R.Oakes@gmail.com> wrote in message
news:1184044623.924785.119680@w3g2000hsg.googlegroups.com...
> I'm new to PHP and I can't get this simple script to run - it gives an
> error on line 31. What am I doing wrong?
>
> Thanks,
> Dan
>
>
> <?php
>
> $message = "";
>
> if ( ! isset( $_POST['guess'] ) ) {
> $message = "This is an if/then, loop program.";
> } else if ( $_POST['guess'] > 101 ) {
> $message = $_POST['guess']." is too big!";
> } else {
> for ($i = 1; $i <= $_POST['guess']; $i++ ) {
> $message = "Number $i\n";
> }
>
> ?>
>
> <html>
> <head>
> <title>If/Then, Loop Program</title>
> </head>
> <body><basefont face="verdana">
> <b>
> <?php print $message ?>
> </b>
> <form method="post" action="<?php print $_SERVER['PHP_SELF']?>">
> <p>
> Type a number: <input type="text" name="guess" />
> <input type="submit" value="submit" />
> </p>
> </form>
> </body>
> </html>
>
hi dan,
you missed a brace (curly bracket) from the for loop
try changing to:
} else {
for ($i = 1; $i <= $_POST['guess']; $i++ ) {
$message = "Number $i\n";
}
}
also if you want to print ALL the numbers up to /including the guess
you want to use:
$message .= "Number $i\n";
(appends to $message)
not
$message = "Number $i\n";
(assign to $message)
cheers,
ED
[Back to original message]
|