Re: Eval error
| From: | Pavel Jartsev | Date: | Thu, 16 Aug 2001 07:41:22 +0000 |
| Subject: | Re: Eval error | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-62984@lists.php.net to get a copy of this message | ||
Felipe Coury wrote:
>
> Hi,
>
> I am a beginner in PHP and I am trying to do the following: I have a form in
> a page that has 3 fields: email_1, email_2 and email_3. I am trying to send
> e-mail to those people, if the fields are filled. Relevant part of code:
>
> <?php
> for ($i = 1; $i <= 6; $i++) {
> $eval = '\$email = \$email_' + $i + ';';
> eval( $eval );
> echo $email;
> }
> ?>
>
> The code complains about an error in line eval( $eval );:
>
> Parse error: parse error in
> /home/httpd/htdocs/hthcombr/cgi-local/envia.php(19) : eval()'d code on line
> 1
>
> Can anyone please help me?
>
Use arrays, it's much easier. Set name of fields like this: email[0],
email[1] and email[2].
Now after submitting the form you have array $email. And for-loop will
be:
<?
for($i=0; $i < sizeof($email); $i++) {
echo $email[$i];
}
?>
Hope this helps.
--
Pavel a.k.a. Papi