简体   繁体   中英

form doesn't redirect to another page in html

I have this form for uploading files on a page called add.php:

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

But when I click the submit button, I don't even get redirected to upload_file.php, I just go back to the same page, add.php. I do have another form on this page which uses method="POST" and that one does redirect to the add.php page. Any help would be appreciated.

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

Your form is nested inside: <form name="input" action="add.php" method="POST"> , and that action is the one executed.

Essentially it looks like this:

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

You need to remove <form name="input" action="add.php" method="POST">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM