2014-01-30 30 views
0

我有這樣的形式上傳一個頁面調用add.php文件:形式不重定向到另一個頁面的HTML

<!DOCTYPE html ISO-8859-1> 
<?php 
include("header.php"); 
include("verbinding.php"); 
if (!isset ($_SESSION["Logged_In"])) 
    { 
     echo header('Location: http://ik42.webdb.fnwi.uva.nl/index.php'); ; 
    } 

if (isset ($_SESSION["Admin"])) 
    { 
    if (!$_SESSION["Admin"] == 1) 
     { 
      echo  header('Location: http://ik42.webdb.fnwi.uva.nl/index.php'); ; 
     } 
    } 
    // clear the value strings 
    $Product = $Afbeelding = $ps4 = $xboxone = $WiiU = $pc = $genre = $prijs = $prijsID = $beschrijving = ""; 
?> 

<h1> Welkom Admin</h1> 

    <br /><br /><hr color="#000000" width="800" ><BR><center> Wil je een product toevoegen?</center><br /><br /> 
      <form name="input" action="add.php" method="POST"> 
       <table id="add"> 
       <tr> 
        <td><b> Producten Toevoegen </b></td> 
       </tr> 
       <tr> 
        <td> <em>Product</em></td> 
         <td> <input type="text" name="Product" value="<?php echo $Product; ?>"> </td> 
       </tr> 
       <tr> 
        <td> <em>Ps4</em> </td> 
         <td> <input type="text" name="ps4" value="<?php echo $ps4; ?>"> </td>     
       </tr> 
       <tr> 
        <td> <em>Xbox One</em> </td> 
         <td> <input type="text" name="xboxone" value="<?php echo $xboxone; ?>"> </td> 
       </tr> 
       <tr> 
        <td> <em>Wii U</em> </td> 
         <td> <input type="text" name="WiiU" value="<?php echo $WiiU; ?>"> </td>   
       </tr> 
       <tr> 
        <td> <em>PC</em> </td> 
         <td> <input type="text" name="pc" value="<?php echo $pc; ?>"> </td>   
       </tr> 
       <tr> 
        <td> <em>Genre</em> </td> 
         <td> <input type="text" name="genre" value="<?php echo $genre; ?>"> </td>   
       </tr> 
       <tr> 
        <td> <em>Prijs</em> </td> 
         <td> <input type="text" name="prijs" value="<?php echo $prijs; ?>"> </td>   
       </tr> 
       <tr> 
        <td> <em>PrijsID</em> </td> 
         <td> <input type="text" name="prijsID" value="<?php echo $prijsID; ?>"> </td>   
       </tr> 
       <tr> 
        <td> <em>Beschrijving</em> </td> 
         <td> <input type="text" name="beschrijving" value="<?php echo $beschrijving; ?>"> </td>   
       </tr> 
        <td> <input type="submit" value="Verzenden"> 
       </tr> 
       <tr> 
        <td><form action="upload_file.php" method="POST" 
         enctype="multipart/form-data"> 
         <label for="file">Filename:</label> 
         <input type="file" name="file" id="file"><br> 
         <input type="submit" name="submit" value="Submit"> 
         </form></td> 
       </tr> 
       </table> 
       <br></br><br></br> 

<?php 
if ($_SERVER["REQUEST_METHOD"] == "POST") { 
    if(!empty($_POST["Product"])){ 
    if(isset($_POST["Product"])) { 

    $sql="INSERT INTO Producten (Product, PS4, XboxOne, WiiU, PC, Genre, Prijs, PrijsID, Beschrijving) 
    VALUES 
    ('$_POST[Product]','$_POST[ps4]','$_POST[xboxone]','$_POST[WiiU]','$_POST[pc]','$_POST[genre]','$_POST[prijs]','$_POST[prijsID]','$_POST[beschrijving]')"; 
    $count = $db->exec($sql); 
     if($count == 1) { 
      echo "Registratie voltooid."; 
      echo "U kunt nu inloggen."; 
     } else { 
      echo "Registratie mislukt, neem contact op met de administrator als dit probleem blijft."; 
     } 

}}} 
?> 

     <?php 
      include("footer.php"); 
      ?>  
     </div> 

    </body> 
</html> 

但是當我點擊提交按鈕,我甚至不重定向upload_file.php,我只是回到同一頁面,add.php。我在這個頁面上有另一個表單,它使用method =「POST」,並且一個重定向到add.php頁面。任何幫助,將不勝感激。

upload_file.php:

<?php  
$allowedExts = array("gif", "jpeg", "jpg", "png"); 
$temp = explode(".", $_FILES["file"]["name"]); 
$extension = end($temp); 
if ((($_FILES["file"]["type"] == "image/gif") 
|| ($_FILES["file"]["type"] == "image/jpeg") 
|| ($_FILES["file"]["type"] == "image/jpg") 
|| ($_FILES["file"]["type"] == "image/pjpeg") 
|| ($_FILES["file"]["type"] == "image/x-png") 
|| ($_FILES["file"]["type"] == "image/png")) 
&& in_array($extension, $allowedExts)) 
    { 
    if ($_FILES["file"]["error"] > 0) 
    { 
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; 
    } 
    else 
    { 
    echo "Upload: " . $_FILES["file"]["name"] . "<br>"; 
    echo "Type: " . $_FILES["file"]["type"] . "<br>"; 
    echo "Size: " . ($_FILES["file"]["size"]/1024) . " kB<br>"; 
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; 

    if (file_exists("/var/www/upload/" . $_FILES["file"]["name"])) 
     { 
     echo $_FILES["file"]["name"] . " already exists. "; 
     } 
    else 
     { 
     move_uploaded_file($_FILES["file"]["tmp_name"], 
     "/var/www/upload/" . $_FILES["file"]["name"]); 
     echo "Stored in: " . "/var/www/upload/" . $_FILES["file"]["name"]; 
     } 
    } 
    } 
else 
    { 
    echo "Invalid file"; 
    } 
?> 
+1

也許你有頭:在你的upload_file.php( 「位置add.php」)。 – pregmatch

+0

不,我不知道。這個頁面上的其他表單不會傷害,對吧? – EerlijkeDame

+0

我們可以看到這個upload_file.php嗎? – pregmatch

回答

0

你的表格嵌套裏面:<form name="input" action="add.php" method="POST">,這動作是執行一個。

本質上,它看起來是這樣的:

<form name="input" action="add.php" method="POST"> 
... 
    <form action="upload_file.php" method="POST" 
         enctype="multipart/form-data"> 
      ... 
     </form> 
... 
</form> 

您需要刪除<form name="input" action="add.php" method="POST">

+1

確實如此,但OP的代碼還有其他的錯誤。這是所有你的;-) –

+0

現在我得到重定向,但我得到:警告:move_uploaded_file(gameimg/Roland.jpg):未能打開流:權限被拒絕。這是否意味着我不允許上傳任何內容? – EerlijkeDame

+0

明天再試一次。現在必須睡覺。多謝你們! – EerlijkeDame

相關問題