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
https://forums.phpfreaks.com/topic/223199-if-statement-in-button-or-new-php/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.