Jump to content

IF statement in button or new php??


jsk1gcc

Recommended Posts

hi again, having trouble getting the result from the drop down box to direct to another page

 

the if statement works when i don't try and do anything with it.

 

should the IF statement go on another page and the submit button POST the $result, i'm really not sure. any help would be great..

 

code so far

 

index.php

<?php
$query = "SELECT * FROM `ride` ORDER BY name";  
$result = mysql_query($query);  

        echo"<select name='name'><option value=''>Select Ride</option>";
                while( $row = mysql_fetch_array($result) ) 
                { 
                echo '<option>'.$row['name'].'</option>'; 
                }  
                        echo '</select>'; 
        mysql_free_result( $result ); 

//// do rest of form when done/////

echo "<form method=post name=f1 action='dd-check.php'>";
echo "<input type=submit value=Submit>";
echo "</form>";

?>

 

dd-check.php

<?php
$result =$_POST['WHAT GOES HERE?']; <-----------???? is this even needed?
echo  "Ride Choosen = $result";     <-----------???? how do i get the $result from index.php?

if ($result == "Swinging Ship") {
                 header('Location: Swing.php');
                } elseif ($result == "Roller Coaster") {
                 header('Location: Roller.php');
                } elseif ($result == "Ice Blast") {
                 header('Location: Ice.php');
                } else {
        echo "choose a ride";
                }
?>

Link to comment
Share on other sites

Your form is not correct, since the drop down list is outside the form definition.

Try something like this:

<?php
echo '<form method="post" name="f1" action="dd-check.php">';
$query = "SELECT * FROM `ride` ORDER BY name";  
$result = mysql_query($query);  

        echo "<select name='name'><option value=''>Select Ride</option>";
                while( $row = mysql_fetch_array($result) ) 
                { 
                echo '<option>'.$row['name'].'</option>'; 
                }  
                        echo '</select>'; 

//// do rest of form when done/////


echo "<input type='submit' value='Submit'>";
echo "</form>";
?>

 

In the processing script:

<?php
$result =$_POST['name']; 
echo  "Ride Choosen = $result";  
//
// etc...
//
?>

 

Ken

Link to comment
Share on other sites

Thankyou,  :D

 

It's messed up how strict and loose php can be, order is everything in this language. Once I get used to it, i'll be fine untill then i'll keep asking for help and learning

 

Thanks again for a quick reply  :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.