Select variable passed to form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Select variable passed to form

Post by pinehead18 »

Code: Select all

 
 
I'm trying to pass the contents of the select input into the form.  It passes "true" as the result.  Any idea how i can get it to pass "all" and "friends" depending on which one is selection via the select option input?
 
Thanks guys,
 
<?PHP
                if(isset($_POST['sort_update'])) {
                    $sort_update = $_POST['sort_update'];
                    if(isset($_POST['all'])) { $update_sort = "all"; } if(isset($_POST['friends'])) { $update_sort = "friends"; }
                    $sql = "UPDATE user_prefs SET sort='$update_sort' WHERE user_id='$user_id'";
                    $result = mysql_query($sql);
                    echo $sql;
                    echo "<br /><br />";
                    echo $sort_update;
                }
                    ?>
 
                        <form id="myform" action="index.php" method="post">
                Sort By: <select onchange="document.getElementById('myform').submit();">
                         <option value="all" name="sort_update" elected="selected">Show</option>
                         <option value="friends" name="sort_update">Show by Friends</option>
                         <input type="hidden" name="sort_update" value="true">
                         </select>
                        </form>
 
 
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: Select variable passed to form

Post by pbs »

Use like this

Code: Select all

 
<?PHP
    
    $sort_update = $_POST['sort_update'];
    if(isset($sort_update)) 
    { 
        if ($sort_update == "all")
            $update_sort = "all"; 
        elseif ($sort_update == "friends")
            $update_sort = "friends"; 
         $sql = "UPDATE user_prefs SET sort='$update_sort' WHERE user_id='$user_id'";
        $result = mysql_query($sql);
        echo $sql;
        echo "<br /><br />";
        echo $sort_update;
    } 
    
?>
 
        <form id="myform" action="index.php" method="post" name="myform">
Sort By: <select onchange="document.myform.submit();" name="sort_update">
             <option value="all" elected="selected">Show</option>
             <option value="friends" >Show by Friends</option>
         </select>
        </form>
 
Post Reply