Re: Register Globals (more)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, November 3, 2005 10:00 pm, John Taylor-Johnston wrote:
> Patience please :)
>
> See my html below. Basically, if type=checkbox is checked, I'm trying
> to build $to string in mail().
>
>>parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING
>> or T_VARIABLE or T_NUM_STRING line 4
>
> How do I rebuild this peice of code to be register_globals=off
> friendly?
> Just when I thought I was getting good. This keeps up, I'm changing
> back the php.ini myself.

Hang in there!

> John
>
>
>
> 1>for ($i = 1; $i <= $_POST["NMax"]; $i++)
> 2>{
> 3>  $CheckVariable = "\{$_POST['Check$i']}";

You don't want ' around Check$i because $ has no special meaning
inside of ''.  Only \ and ' mean anything special to ''.



> 4>	eval("\$CheckVariable = \"$CheckVariable\";");

Woof.

You could save a WHOLE bunch of trouble making a change (below) and
doing:

$names = $_POST['names'];
$emails = $_POST['emails'];
$checks = isset($_POST['checks']) ? $_POST['checks'] : array();
foreach($names as $i => $name){
  $email = $emails[$i];
  $check = isset($checks[$i]);
  echo "$name: $email ($check)<br />\n";
}

Even so, you sure don't need eval() even if you want to keep
everything else the same:

$name = $_POST["name$i"];
$email = $_POST["email$i"];
//HTTP doesn't send anything for un-checked checkboxes.
$check = isset($_POST["check$i"]);

> 5>  $nameVariable = "\{$_POST['name$i']}";
> 6>	eval("\$nameVariable = \"$nameVariable\";");
> 7>  $emailVariable = "\{$_POST['email$i']}";
> 8>	eval("\$emailVariable = \"$emailVariable\";");
> 9>
> 10>#echo ${"Check$i"};
> 11>#echo "$CheckVariable $emailVariable - $i<br>";
> 12>
> 13>if ($CheckVariable)
> 14>$to .= "\"$nameVariable\" <".$emailVariable.">,";

$to .= "\"$name\" <$email>,";

> 15>
> 16>}
> 17>
> 18>echo $to;
>
>
> <INPUT TYPE="checkbox" NAME="Check1" VALUE="John" CHECKED>"John"

Change this to:
NAME="check[1]"

> <input type="hidden" name="name1" value="John">

NAME="name[1]"

> <input type="hidden" name="email1" value="John_cy@xxxxxxx">

NAME="email[1]"

> <br>
> <INPUT TYPE="checkbox" NAME="Check2" VALUE="Alessandra"

NAME="check[2]"

> CHECKED>"Alessandra"
> <input type="hidden" name="name2" value="Alessandra">

NAME="name[2]"

> <input type="hidden" name="email2" value="alessandra_cy@xxxxxxx">

NAME="email[2]"

> <br>
> ...

...

> <input type="hidden" name="NMax" value="29">

You may not even need this any more...

The arrays are going to be as big as they need to be, and no bigger.

Like a woman's skirt should be. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux