On Fri, 17 Oct 2003 14:42:34 +0800, you wrote:

>Right now, I am able to change the colour of cells using a drop down menu, and
>when I clicked on "Reload" it still remains the colour that I have changed, but
>when I open the page in another browser, as I echoed the value "colour", the
>browser displayed a mixture of the colour code :grey, pink, blue, etc....
>How can I do it in the way that when I opened up a new browser it will display
>only the colour that I have changed to earlier on?....Hope to get some help
>soon...thanks for all help given.

You're trying to hold state. To do this, you need to use a cookie or a
session.

There are also several problems with the script you seem to be using (for
example, it's open to code injection). Hopefully, you'll be able to tease
some sense out of this:

<?
    $valid_colours = array ('Grey' => '#dedede', 'Pink' => '#ffb6c1',
                            'Blue' => '#87ceeb', 'Yellow' => '#ffff00',
                            'Cyan' => '#afeeee'); /* valid responses */

    session_start();

    if (isset ($_POST['textcolour']))
    {
        /* check that incoming textcolour is one of the permitted values */
        if (in_array ($_POST['textcolour'], $valid_colours))
        {
            $_SESSION['textcolour'] = $_POST['textcolour'];
            header ("Location: $PHP_SELF");
            exit ();
        }
    }

    /* if we don't have a colour, default to grey */
    if (isset ($_SESSION['textcolour']) == FALSE)
    {
        $_SESSION['textcolour'] = $valid_colours['Grey'];
    }

?>
<html>
    <body>
        <table bgcolor="<? echo ($_SESSION['textcolour']); ?>">
            <tr><td>Test</td></tr>
        </table>
        <form method="post" action="<? echo ($PHP_SELF); ?>">
            <select name="textcolour">
<?
    foreach ($valid_colours as $colour => $value)
    {
        if ($value == $_SESSION['textcolour'])
        {
            echo ("<option value=\"$value\" selected>$colour</option>");
        } else {
            echo ("<option value=\"$value\">$colour</option>");
        }
    }
?>
            </select>
            <input type="submit" name="change" value="Change">
        </form>
    </body>
</html>

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

Reply via email to