Todd Cary <mailto:[EMAIL PROTECTED]>
    on Sunday, September 14, 2003 9:34 AM said:

> I may have two buttons on the form and the Form Action has the same
> value as the current form, then at the top of my php script, I may
> have 

I've never done this but can you give the two buttons the same name but
different values? Assuming the value of the button that is clicked is
the only value you sent you can clean up the code a little.

$buttonPressed = $_POST['button'];

($HTTP_POST_VARS is deprecated [afaik])

(also notice i put single quotes around the index, you should too)

your code:

> if ($continue) {
>   //Do something - usually go to another page
> } elseif {
> ($cancel) {
>   // Do something - usually go to another page
> } else {
>   //Do something
> }

my code:

if ($button == "value1")
{
        // do this stuff
}
elseif($button == "value2")
{
        // do this stuff instead
}
else
{
        // do this instead
}

> Is this inefficient or is there a better way to do this?

Yes it is because your testing only for the existence of a value and not
a specific value. This could allow a malicious user to fudge around with
your form, submit their own values, and possibly have your code react in
a way you wouldn't want it to.


your code:
>         echo(NL);
>         echo('<td class="' . $class . '"><b>' . $date . "</b></td>");
>         echo(NL);
>         echo('<td class="' . $class . '"><b>' . $place . "</b></td>");
>         echo(NL);
>         echo('<td class="' . $class . '"><b>' . $est_amt .
>         "</b></td>"); echo(NL);
>         echo('<td class="' . $class . '"><b>' . $card . "</b></td>");
>         echo(NL);
>         echo('<td class="' . $class . '"><b>' . $ccn . "</b></td>");
>         echo(NL);
>         echo('<td class="' . $class . '"><b>' . $state . "</b></td>");
>         echo(NL);

How about this instead? (btw, i've never used NL so i'm going to assume
it's the equivalent of \n)

echo "<td class=\"$class\"><b>$date</b></td>\n"
        ."<td class=\"$class\"><b>$place</b></td>\n"
        ."<td class=\"$class\"><b>$est_amt</b></td>\n"
        ."<td class=\"$class\"><b>$card</b></td>\n"
        ."<td class=\"$class\"><b>$ccn</b></td>\n"
        ."<td class=\"$class\"><b>$state</b></td>\n";

Isn't that so much easier to read???


HTH,
Chris.

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

Reply via email to