简体   繁体   中英

HTML/PHP Form for upload

May be a little bit noob thing but I'm tired and have no idea why it's not working, I can't ask my teacher because its Sunday and i want to keep the program today.

I have a form, for a cms. Where you can update text of that page but I also want to be albe to upload a image. However, when I place my label ect for the image upload I get alot of errors.

On this code under beneath I have the form for the upload under the code where I want to have it. I will place a //Here where I want it. So you guys understand what I want. Thank you for your help.

<?php
    $sql = "SELECT * FROM home";
    $result = mysqli_query($db, $sql);

    while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
    echo "<h3>Gegevens van record " . $row["ID"] . "</h3>";
    echo "<form name='update{$row["ID"]}'

    <form action='cms_home_update.php' method='POST'>
        <input type='hidden' name='id' value='{$row["ID"]}'>
        <p>Titel</p>
        <input type='text' name='Titel' size='75' value='{$row["Titel"]}'><br><p>Tekst</p>
        <textarea name='Tekst' rows='10' cols='100'>";

        echo html_entity_decode(stripslashes($row["Tekst"]), ENT_QUOTES);
        echo "</textarea><br>

        //Here i wanted to have to be able to also upload a image

        <input type='submit' name='button' value='Updaten'>
    </form>";

    echo"<h3>Plaatje van " . $row["ID"] . "</h3>";
?>
    //Here i have the upload form how to make it to be able to standing on here i wanted       
    <form action="cms_home_image.php" method="post"
        enctype="multipart/form-data">
        <label for="file">Kies je bestand.</label>
        <input type="file" name="file" id="file"><br>
        <input type="submit" name="submit" value="Versturen">
    </form>
    <?php
    }
?>

First of all, this has some constructive mistakes:

Here you open two <form> tags:

echo "<form name='update{$row["ID"]}'    
<form action='cms_home_update.php' method='POST'>

You must also escape your quotes around the index on the $row array, since you start your string with double quotes " too:

"…$row[\"ID\"]…"

Either that or concatenate your value:

"…".$row["ID"]."…"

And to update a file, you need this input element:

<input type="file" name="file" id="file">

Then on your PHP script you can use any of these to handle the object (quoting from w3c pages: PHP File Upload ):

$_FILES["file"]["name"] // the name of the uploaded file
$_FILES["file"]["type"] // the type of the uploaded file
$_FILES["file"]["size"] // the size in bytes of the uploaded file
$_FILES["file"]["tmp_name"] // the name of the temporary copy of the file stored on the server
$_FILES["file"]["error"] // the error code resulting from the file upload

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