You are here: Re: PHP Help « PHP Programming Language « IT news, forums, messages
Re: PHP Help

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация