开发者

POST problem - Undefined index

can anybody tell me what is wrong with this code, i am getting the following error

Notice: Undefined index: media_type in C:\wamp\www\VirtualLibrary\upload_file.php on line 10

Notice: Undefined index: file in C:\wamp\www\VirtualLibrary\upload_file.php on line 14

Notice: Undefined index: file in C:\wamp\www\VirtualLibrary\upload_file.php on line 20

Notice: Undefined index: file in C:\wamp\www\VirtualLibrary\upload_file.php on line 22

here is my code

<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>
                    <?php if(isset($_SESSION['login_user']))
                    { 
                        $uname = $_SESSION['login_开发者_开发技巧user'];
                        echo "<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>
             <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&nbsp;</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'>
                    }


        </div>
    </body>
</html>

and here is the upload_file.php

<?php
    require('include/connection.php');
    session_start();
?>
<?php   
foreach ($_POST as $var => $value) { 
    echo "$var = $value<br>n"; 
}

$meditype = $_POST['media_type'];



               if ($_FILES["file"]["error"] > 0) 
                    {
                      echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
                    }
               else 
                   { 
                       if (file_exists($meditype . "/" . $_FILES["file"]["name"])) 
                                  {
                                      echo $_FILES["file"]["name"] . " already exists. ";
                                  }
                            else 
                                { 
                move_uploaded_file($_FILES["file"]["tmp_name"], $meditype . "/" . $_FILES["file"]["name"]);

                                } 
                               }




?>


You are not checking to see if the post data exists. Use isset to do that. Ex

if (isset($_POST['media_type'])) {
  // Media type field was posted
}


Please do not create separate questions for the same underlying issue: Getting the value of a combo-box using post method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜