Page 1 of 1

IF statement in button or new php??

Posted: Sun Jan 02, 2011 8:57 am
by jsk1gcc
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

Code: Select all

<?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

Code: Select all

<?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";
                }
?>

Re: IF statement in button or new php??

Posted: Sun Jan 02, 2011 9:14 am
by jankidudel
1. If you something have written in your page, the header('Location: ,.......) won't work, from php.net >>Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code <<

2. In index.php you write a form, then on submit, you go to another page, then this another page redirects to your option, but you can do it on 1 file.

example

if(isset($_POST['your_form_data_name']))
{
.......