Hallo allemaal.

Ik wil een plaat je beeld brengen met php. (Dit moet uiteindelijk een boek worden, maar das hier relevant)

Nu heb ik de volgende code:

idex.php
<?php
require_once('./operations.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image Upload</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<body>
    <h1 class="text-center my- 3" >Registration Form</h1>
    <div class = "container d-flex justify-content-center">
    <form action="display.php" method= "POST" class="w-50" enctype="multipart/form-data">

            <?php

            echo inputFields("Username","username","","text");
            echo inputFields("Mobile","mobile","","text");
            echo inputFields("","file","","file");
            ?>
            <button class="btn btn-dark" type="submit" name = "submit">Submit</button>
           
        </form>
    </div>
</body>
</html>


connect.php
<?php

$con = mysqli_connect('localhost', 'root', 'usbw', 'ImageUploadProject');
if(!$con)
{
    die(mysqli_error($con));
}

?>


connect.php
<?php

$con = mysqli_connect('localhost', 'root', 'usbw', 'ImageUploadProject');
if(!$con)
{
    die(mysqli_error($con));
}

?>


Nu krijg ik de volgende foutmelding:

Connection Succesful
Notice: Undefined index: file in C:\USB WebServer\root\Youtube9\display.php on line 8
ed
2
Displaying Data

Wat is hier het probleem?
Het probleem zal in display.php op lijn 8 zitten.
Blijkbaar roep je een waarde aan die niet bestaat.
Oeps iets vergeten.....

<?php

include ('./connect.php');
if(isset($_POST['submit']))
{
    $username = $_POST['username'];
    $mobile = $_POST['mobile'];
    $image = $_FILES['file'];
    echo $username;
    echo "<br>";
    echo $mobile;
    echo "<br>";
}
    

?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Display Data</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<body>
    <h1>Displaying Data</h1>
</body>
</html>


Hoi,

Het bestand wat ontbrak....

[size=xsmall]Toevoeging op 09/05/2022 18:02:14:[/size]

De laatste is dus display.php
Hoe ziet je upload-formulier eruit?
das idex.php (bij mij index.php). Dat zit er dus bij
Ik zie daar geen upload formulier. Hoe ziethet formulier eruit als HTML-code?
<?php
require_once('./operations.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image Upload</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<body>
    <h1 class="text-center my- 3" >Registration Form</h1>
    <div class = "container d-flex justify-content-center">
    <form action="display.php" method= "POST" class="w-50" enctype="multipart/form-data">

            <?php

            echo inputFields("Username","username","","text");
            echo inputFields("Mobile","mobile","","text");
            echo inputFields("","file","","file");
            ?>
            <button class="btn btn-dark" type="submit" name = "submit">Submit</button>
           
        </form>
    </div>
</body>
</html>



[size=xsmall]Toevoeging op 09/05/2022 18:57:52:[/size]

Das mijn index.php. Daar wordt ook alles geupload
Maar ik zie nog geen formulier.
Daarom vraag ik ook de HTML-code. Dus tover die eens uit je browser.
die staat er toch boven? ik snap hem anders niet
Kijk, de code (nog met de fout) :

 <?php

function inputFields($placeholder,$name,$value,$type)
{
    
    $ele="
    <div class=\"form-group my-4\">
    <input tyoe ='$type' name='$name' placeholder='$placeholder' class=\"form-control\" value='$value' autocomplete =\"off\">
    </div>
    
    ";
    echo $ele;
}


?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image Upload</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<body>
    <h1 class="text-center my- 3" >Registration Form</h1>
    <div class = "container d-flex justify-content-center">
    <form action="display.php" method= "POST" class="w-50">

            
    <div class="form-group my-4">
    <input type ='text' name='username' placeholder='Username' class="form-control" value='' autocomplete ="off">
    </div>
    
    
    <div class="form-group my-4">
    <input type ='text' name='mobile' placeholder='Mobile' class="form-control" value='' autocomplete ="off">
    </div>
    
    
    <div class="form-group my-4">
    <input type ='file' name='file' placeholder='' class="form-control" value='' autocomplete ="off">
    </div>
    
                <button class="btn btn-dark" type="submit" name = "submit">Submit</button>
           
        </form>
    </div>
</body>
</html>

Reageren