Posted by Tom on 04/16/07 18:49
On Mon, 16 Apr 2007 13:06:33 -0500, DrNoose wrote...
>
>Hi!
>
>I have followed the previous threads and tried some of the suggestions,
>but still could not get my code to run. When I select a button and hit
>the "Pick A Color" button, nothing happens. I've included the code for
>the html form and the .php file. The book I've been reading suggests
>using If/else statements. I saw that some else had used switch
>statements. I did try using a switch statement, but it didn't work. The
>code below uses the if/else statements. I was also not sure if I should
>put the $_POST statement in the if/else since I had used "extract
>"$_POST" earlier.
>
>Any help is appreciated!
I'd check some of the syntax on your code. I believe your $_POST variables need
single quotes around the name such as "$_POST['PickColor']" and your first if
statement
if ($_POST[PickAColor == "")
will probably make the page not work at all. It's missing the closing "]".
Tom
--
Newsguy.com - Basic Accounts $39.95 / 12 months
>
>**************************************************************************
>
><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
><html xmlns="http://www.w3.org/1999/xhtml" >
> <head>
> <title>Pick A Color</title>
> </head>
> <body>
> <form method="post" action="PickAColor.php">
> <p style="text-align: center">
> <strong><span style="font-size: 24pt">Pick A
>Color</span></strong></p>
> <p>
> </p>
> <p>
> <strong><span style="font-size: 16pt" title="Red">
> <input id="btnRed" name="PickColor" type="radio"
>value="Red" />Red</span></strong></p>
> <p>
> <strong><span style="font-size: 16pt" title="Red">
> <input id="btnBlue" name="PickColor" tabindex="1"
>type="radio" value="Blue" />Blue</span></strong></p>
> <p>
> <strong><span style="font-size: 16pt" title="Red">
> <input id="btnGreen" name="PickColor" tabindex="2"
>type="radio" value="Green" />Green</span></strong></p>
> <p>
> <input id="btnPickColor" name="PickColor" type="button"
>value="Pick A Color" /> </p>
> <p>
> <strong><span style="font-size: 16pt"
>title="Red"></span></strong> </p>
>
> </form>
> </body>
> </html>
>
><?php
> // Get the information from the form
> extract($_POST);
> // Determine if the data is blank
> if ($_POST[PickAColor == "")
> {
> header("Location: index.html");
> exit;
> }
>
> // Determine what index was selected
> if ($_POST[PickColor] == "Red") {
> $resultIndex = 0;
>
> } else if ($_POST[PickColor] == "Blue") {
> $resultIndex = 1;
>
> } else if ($_POST[PickColor] == "Green") {
> $resultIndex = 2;
> }
>
> // Determine what color was selected
> if ($_POST[PickColor] == "Red") {
> $resultColor = Red;
>
> } else if ($_POST[PickColor] == "Blue") {
> $resultColor = Blue;
>
> } else if ($_POST[PickColor] == "Green") {
> $resultColor = Green;
> }
>?>
><html>
> <head>
> <title>Pick A Color</title>
> </head>
> <body>
> <p> You selected Index Number: <?php echo $resultIndex"; ?></p>
> <p> The color you selecte is: <?php echo "$resultColor"; ?></p>>
>
> </body>
></html>
[Back to original message]
|