Plaatje in beeld brengen met PHP

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Ed Jeurissen

Ed Jeurissen

09/05/2022 17:45:55
Quote Anchor link
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
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
<?php

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

    die(mysqli_error($con));
}


?>


connect.php
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
<?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?
 
PHP hulp

PHP hulp

18/04/2024 13:24:42
 
- Ariën  -
Beheerder

- Ariën -

09/05/2022 17:48:31
Quote Anchor link
Het probleem zal in display.php op lijn 8 zitten.
Blijkbaar roep je een waarde aan die niet bestaat.
 
Ed Jeurissen

Ed Jeurissen

09/05/2022 17:56:43
Quote Anchor link
Oeps iets vergeten.....

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?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....

Toevoeging op 09/05/2022 18:02:14:

De laatste is dus display.php
Gewijzigd op 09/05/2022 19:20:34 door - Ariën -
 
- Ariën  -
Beheerder

- Ariën -

09/05/2022 18:05:41
Quote Anchor link
Hoe ziet je upload-formulier eruit?
 
Ed Jeurissen

Ed Jeurissen

09/05/2022 18:24:13
Quote Anchor link
das idex.php (bij mij index.php). Dat zit er dus bij
 
- Ariën  -
Beheerder

- Ariën -

09/05/2022 18:33:48
Quote Anchor link
Ik zie daar geen upload formulier. Hoe ziethet formulier eruit als HTML-code?
Gewijzigd op 09/05/2022 18:34:45 door - Ariën -
 
Ed Jeurissen

Ed Jeurissen

09/05/2022 18:57:10
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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>



Toevoeging op 09/05/2022 18:57:52:

Das mijn index.php. Daar wordt ook alles geupload
Gewijzigd op 09/05/2022 19:20:22 door - Ariën -
 
- Ariën  -
Beheerder

- Ariën -

09/05/2022 19:01:15
Quote Anchor link
Maar ik zie nog geen formulier.
Daarom vraag ik ook de HTML-code. Dus tover die eens uit je browser.
 
Ed Jeurissen

Ed Jeurissen

09/05/2022 19:08:33
Quote Anchor link
die staat er toch boven? ik snap hem anders niet
 
Adoptive Solution

Adoptive Solution

09/05/2022 19:11:47
Quote Anchor link
Kijk, de code (nog met de fout) :

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?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;
}



?>
 
Ed Jeurissen

Ed Jeurissen

09/05/2022 19:13:12
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!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>
Gewijzigd op 09/05/2022 19:20:08 door - Ariën -
 
Adoptive Solution

Adoptive Solution

09/05/2022 19:13:14
Quote Anchor link
En hier een script om een bestand te uploaden :

https://www.w3schools.com/php/php_file_upload.asp
 
- Ariën  -
Beheerder

- Ariën -

09/05/2022 19:19:46
Quote Anchor link
Je form-tag klopt niet, je mist een enctype.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<form action="display.php" method="post" enctype="multipart/form-data">
Gewijzigd op 09/05/2022 19:20:54 door - Ariën -
 
Adoptive Solution

Adoptive Solution

09/05/2022 19:31:22
 
- Ariën  -
Beheerder

- Ariën -

09/05/2022 19:39:06
Quote Anchor link
Dan heb ik niks gezegd... ;-)
Ik denk eerder dat dat er niks ingevuld is als upload.
 
Ed Jeurissen

Ed Jeurissen

09/05/2022 21:41:31
Quote Anchor link
Hoii Arien,

er wordt wel degelijk iets ingevuld!

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

Je aanpassing ha ik al gedaan, maar levert helaas niet het gewenste resultaat op.
 
- Ariën  -
Beheerder

- Ariën -

09/05/2022 22:23:25
Quote Anchor link
Plaats dit eens op de plek waar je gecontroleerd heb of je formulier verzonden is?

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
echo "<h1>POST</h1><pre>".print_r($_POST,true)."</pre>";
echo "<h1>FILES</h1><pre>".print_r($_FILES,true)."</pre>";
 
Ed Jeurissen

Ed Jeurissen

09/05/2022 22:37:11
Quote Anchor link
Het werkt nu wel!
 
- Ariën  -
Beheerder

- Ariën -

09/05/2022 22:47:51
Quote Anchor link
Wat was de oplossing dan? Wil je die met ons delen?
Gewijzigd op 09/05/2022 22:48:04 door - Ariën -
 
Ed Jeurissen

Ed Jeurissen

10/05/2022 16:29:21
Quote Anchor link
Ja hoor!


Index.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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="" class="w-50">

            <?php

            return $ele;
            function
inputFields("Username","username","","text");
            function
inputFields("Mobile","mobile","","text");
            function
inputFields("","file","","file");

            ?>

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


Operations.php
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
<?php

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

    die(mysqli_error($con));
}


?>


display.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
<!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>Displying Data</h1>
</body>
</html>


connect.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
<?php

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

    die(mysqli_error($con));
}


?>
Gewijzigd op 10/05/2022 16:37:24 door - Ariën -
 
Ivo P

Ivo P

10/05/2022 16:39:02
Quote Anchor link
Ik denk dat met "wat was de oplossing" meer bedoeld werd dat je een antwoord gaf als "ik was een komma vergeten" , of "het veld heette niet File, maar Bestand"

Niemand gaat regel voor regel die 60 regels code regel voor regel vergelijken
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.