使用post方法获取组合框的值

时间:2011-08-12 16:20:35

标签: php html

我想用php来获取组合框的值,我正在使用post方法... 任何人都可以告诉我如何。

<html>
    <head>
        <title>Virtual Library</title>
        <link href="css/login.css" rel="stylesheet"/>
        <link href="css/style.css" rel="stylesheet"/>
        <script type="text/javascript" src="scripts/ajax_search.js"></script>
    </head>
    <body>
        <div id="wrapper">
            <div id="header" align="center">
                <ul align="center">
                    <li><a href="index.php"><span>Home</span></a></li>
                    <li><a href="news.html"><span>Top 100 Downloads</span></a></li>
                    <li><a href="upload.php"><span>Upload</span></a></li>
                    <?php if(isset($_SESSION['login_user']))
                    { 
                        $uname = $_SESSION['login_user'];
                        echo "<li><a href='profile.php'><span>$uname</span></a></li>";
                        echo "<li><a href='logout.php'><span>LogOut</span></a></li>";
                    }
                    else{
                            echo "<li><a href='login.php'><span>Member Login</span></a></li>";
                            echo "<li><a href='register.php'><span>Register</span></a></li>";
                        }
                    ?>
                    <li><a href="downloads.html"><span>RSS <img src="images/rss.gif" id="rss"></span></a></li>
                </ul>
            </div>
            <?php if(isset($_SESSION['login_user']))
                    { 
                            echo "<div class='frmdiv'>
                                <form action='upload_file.php' method='post' enctype='multipart/form-data'> 
                                <table width='38%' border='0' align='center' cellpadding='0' cellspacing='0'>
                                <tr> 
                                    <td colspan='2'><div align='center'><font size='2' face='verdana'>Upload File</font></div></td>
                                </tr>
                                <tr> 
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                </tr>
                                <tr> 
                                    <td colspan='2'><hr></td>
                                </tr>
                                <tr> 
                                    <td height='26'><font size='2' face='verdana'>FileName</font></td>
                                    <td><font size='2' face='verdana'> 
                                    <input type='file' name='file' ></font>
                                    </td>
                                </tr>
                                <tr> 
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                </tr>
                                <tr> 
                                    <td></td>
                                    <td><select name='media_type' >
                                    <option value='' selected>Select a media type...</option>
                                    <option value='pdf'>PDF</option>
                                    <option value='chm'>CHM</option>
                                    <option value='epub'>EPUB</option>
                                    <option value='html'>HTML</option>
                                    <option value='djvu'>DJVU</option>
                                    </select></td>
                                </tr>
                                <tr> 
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                </tr>
                                <tr> 
                                    <td>&nbsp;</td>
                                    <td><font size='2' face='verdana'> 
                                    <input type='submit' name='Submit' value='Upload'></font>
                                    </td>
                                </tr>
                                <tr> 
                                    <td colspan='2'><hr></td>
                                </tr>
                                <tr> 
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                </tr>
                                </table>
                                </form>
                                <div align='center'>";
                    }
                    else{
                            echo "<script type='text/javascript'>";
                            echo "alert('You Must Be Logged In To Upload');";
                            echo "location='login.php'";
                            echo "</script";

                        }
            ?>
        </div>
    </body>
</html>

这是组合框。

1 个答案:

答案 0 :(得分:5)

尝试:

if(isset($_POST['media_type']){
   $value = $_POST['media_type'];
}

更新:由于这不适合您,请检查您是否收到任何帖子变量:

foreach ($_POST as $var => $value) { 
    echo "$var = $value<br>n"; 
}