Probleem met mysqli_fetch_assoc

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Ed Jeurissen

Ed Jeurissen

03/12/2021 17:39:54
Quote Anchor link
Hallo,

Weer een foutmelding:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given in C:\USB WebServer\root\CRUD\display.php on line 44

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
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<html>
    <head>
        <title>CRUD Operation</title>
        <script src = https://code.jquery.com/jquer-2.1.3.min.js></script>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    </head>
    <body>
        <div class = "containerr">
        
            <button class = "btn btn-primary my-5" ><a href="user.php" class="text-light">Add User</a>
        


            </button>

            <table class="table">
            <thead>
                <tr>
                <th scope="col">ID</th>
                <th scope="col">Voornaam</th>
                <th scope="col">Achternaam</th>
                <th scope="col">email</th>
                <th scope="col">telefoonnummer</th>
                <th scope="col">adres</th>
                <th scope="col">postcode</th>
                <th scope="col">woonplaats</th>
                <th scope="col">username</th>
                <th scope="col">password1</th>
                <th scope="col">password2</th>
                <th scope="col">geslacht</th>
                <th scope="col">geboortedatum</th>
                </tr>
            </thead>
            <tbody>

            <?php

            include 'connect.php';

            $sql = "SELECT * FROM crudoperation ";
            $result = mysqli_query($con, $sql);
            if($result)
            {

                $row = mysqli_fetch_assoc($con, $result);
            }




            ?>

            
            </tbody>
            </table>

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


user.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
29
30
31
32
<?php
include 'connect.php';
if(isset($_POST ['submit']))
{

 // $name =$_POST['name'];
  $voornaam = isset($_POST['voornaam']) && trim($_POST['voornaam'])!='' ? $_POST['voornaam'] : '';
  $achternaam = isset($_POST['achternaam']) && trim($_POST['achternaam'])!='' ? $_POST['achternaam'] : '';
  $email = isset($_POST['email']) && trim($_POST['email'])!='' ? $_POST['email'] : '';
  $telefoonnummer = isset($_POST['telefoonnummer']) && trim($_POST['telefoonnummer'])!='' ? $_POST['telefoonnummer'] : '';
  $adres = isset($_POST['adres']) && trim($_POST['adres'])!='' ? $_POST['adres'] : '';
  $postcode = isset($_POST['postcode']) && trim($_POST['postcode'])!='' ? $_POST['postcode'] : '';
  $woonplaats = isset($_POST['woonplaats']) && trim($_POST['woonplaats'])!='' ? $_POST['woonplaats'] : '';
  $username = isset($_POST['username']) && trim($_POST['username'])!='' ? $_POST['username'] : '';
  $password1 = isset($_POST['password1']) && trim($_POST['password1'])!='' ? $_POST['password1'] : '';
  $password2 = isset($_POST['password2']) && trim($_POST['password2'])!='' ? $_POST['password2'] : '';
  $geslacht = isset($_POST['geslacht']) && trim($_POST['geslacht'])!='' ? $_POST['geslacht'] : '';
  $geboortedatum = isset($_POST['geboortedatum']) && trim($_POST['geboortedatum'])!='' ? $_POST['geboortedatum'] : '';

  $sql = "INSERT INTO crudoperation (voornaam, achternaam, email, telefoonnummer, adres, postcode, woonplaats, password1, password2, geslacht, geboortedatum) VALUES (' $voornaam', '$achternaam', '$email', '$telefoonnummer', '$adres','$postcode', '$woonplaats', '$username', '$password1', '$password2', '$geslacht', '$geboortedatum')";

  $result = mysqli_query($con,$sql);

  if($result)
  {

    echo "Data inserted succelfully";
  }

  else
  {
    die(mysqli_error($con));
  }
}

?>


user.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

    <title>CRUD Operation</title>
  </head>
  <body>
    <div class="container my -5"></div>
    <form method = post>
        <div class="form-group">
            <label>Voornaam</label>
            <input type="text" class="form-control" placeholder ="Enter your name" name= "voornaam" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>Achternaam</label>
            <input type="text" class="form-control" placeholder ="Enter your email" name= "achternaam" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>email</label>
            <input type="email" class="form-control" placeholder ="Enter your mobile" name= "email" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>telefoonnummer</label>
            <input type="text" class="form-control" placeholder ="Enter your password" name= "telefoonnummer" autocomplete="off" required>
        </div>
        <div class="form-group">
            <label>adres</label>
            <input type="text" class="form-control" placeholder ="Enter your name" name= "adres" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>postcode</label>
            <input type="text" class="form-control" placeholder ="Enter your postcode" name= "postcode" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>woonplaats</label>
            <input type="text" class="form-control" placeholder ="Enter your woonplaats" name= "woonplaats" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>username</label>
            <input type="text" class="form-control" placeholder ="Enter your username" name= "username" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>password</label>
            <input type="password" class="form-control" placeholder ="Enter your password" name= "password1" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>password</label>
            <input type="password" class="form-control" placeholder ="Enter your password again" name= "password2" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>geslacht</label>
            <input type="text" class="form-control" placeholder ="Enter your geslacht" name= "geslacht" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>geboortedatum</label>
            <input type="text" class="form-control" placeholder ="Enter your geboortedatum" name= "geboortedatum" autocomplete="off" required>
        </div>


        <button type="submit" class="btn btn-primary" name= "submit" >Submit</button>
    </form>

    </div>

  
  </body>
</html>
[//code]

In user.php zitten geen fouten!!

Alleen in display. Wat doe ik hier fout?

[modedit]
Titel aangepast van 'overzicht' naar 'Probleem met mysqli_fetch_assoc'
Gelieve in het vervolg duidelijke maar kort en bondige topictitels te gebruiken die de vraag of het probleem omschrijven.
[/modedit]
Gewijzigd op 06/12/2021 13:53:33 door - Ariën -
 
PHP hulp

PHP hulp

19/03/2024 07:27:17
 
- Ariën  -
Beheerder

- Ariën -

03/12/2021 18:11:43
Quote Anchor link
Waar komt $con vandaan?
Daar klopt iets niet omdat het een object is.
Gewijzigd op 03/12/2021 18:15:12 door - Ariën -
 
Ed Jeurissen

Ed Jeurissen

03/12/2021 18:16:25
Quote Anchor link
uit de volgende:

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

        $host
= "localhost";
        $user = "root";
        $password ="usbw";
        $db = "crud";

        $con = new mysqli( $host, $user, $password, $db );

        //nodig $voornaam = isset($_POST['voornaam']) && trim($_POST['voornaam'])!='' ? $_POST['voornaam'] : '';
        //$voornaam = $_POST ['voornaam'];
        //nodig $achternaam = isset($_POST['achternaam']) && trim($_POST['achternaam'])!='' ? $_POST['achternaam'] : '';
        //$achternaam = $_POST ['achternaam'];
        //nodig $email = isset($_POST['email']) && trim($_POST['email'])!='' ? $_POST['email'] : '';
        //$email = $_POST ['email'];
        //nodig $telefoon = isset($_POST['telefoon']) && trim($_POST['telefoon'])!='' ? $_POST['telefoon'] : '';
        //$telefoon = $_POST ['telefoon'];
        //nodig $adres = isset($_POST['adres']) && trim($_POST['adres'])!='' ? $_POST['adres'] : '';
        //$adres = $_POST ['adres'];
        //nodig $postcode = isset($_POST['postcode']) && trim($_POST['postcode'])!='' ? $_POST['postcode'] : '';
        //$postcode = $_POST ['postcode'];
        //nodig $woonplaats = isset($_POST['woonplaats']) && trim($_POST['woonplaats'])!='' ? $_POST['woonplaats'] : '';
        //$woonplaats = $_POST ['woonplaats'];
        //nodig $gebruikersnaam = isset($_POST['username']) && trim($_POST['username'])!='' ? $_POST['username'] : '';
        //$gebruikersnaam = $_POST ['username'];
        //nodig $password1 = isset($_POST['password1']) && trim($_POST['password1'])!='' ? $_POST['password1'] : '';
        //$password1 = $_POST ['password1'];
        //nodig $password2 = isset($_POST['password2']) && trim($_POST['password2'])!='' ? $_POST['password2'] : '';
        //$password2 = $_POST ['password2'];
        //nodig $geslacht = isset($_POST['geslacht']) && trim($_POST['geslacht'])!='' ? $_POST['geslacht'] : '';
        //$geslacht = $_POST ['geslacht'];
        //nodig $geboortedatum = isset($_POST['geboortedatum']) && trim($_POST['geboortedatum'])!='' ? $_POST['geboortedatum'] : '';
        //$geboortedatum = $_POST ['geboortedatum'];
        //nodig $usertype = isset($_POST['usertype']) && trim($_POST['usertype'])!='' ? $_POST['usertype'] : '';
        //$usertype = $_POST ['usertype'];

        //nodig $query = "INSERT INTO user (voornaam, achternaam, email, telefoon, adres, postcode, woonplaats, username, password1, password2, geslacht, geboortedatum, usertype)  VALUES ('" . $voornaam . "', '". $achternaam . "', '". $email . "', '". $telefoon . "', '". $adres . "', '". $postcode . "', '". $woonplaats . "', '". $gebruikersnaam . "', '". $password1 . "', '". $password2 . "', '". $geslacht . "', '". $geboortedatum . "', '". $usertype . "' )";

        //echo '<p>' . $query . '</p>';

        //nodig $run =new mysqli_query ($data, $query); // or mysqli_error($data);


        if(!$con)

        {

            echo "Form not submitted";
            // nodig $fout = mysqli_error($data);
            //echo '<p>' . $fout . '</p>';

        }

        ?>


Maar zit geen foutmelding!
 
- Ariën  -
Beheerder

- Ariën -

03/12/2021 18:17:52
Quote Anchor link
Connectie is niet nodig in mysqli_fetch_assoc.
 
Ed Jeurissen

Ed Jeurissen

04/12/2021 14:50:10
Quote Anchor link
Hoi,

nog een foutmelding!

Column count doesn't match value count at row 1

Waar komt die vandaan?

Die zit in user.php
 
- Ariën  -
Beheerder

- Ariën -

04/12/2021 15:10:21
Quote Anchor link
Vertalen is gelukkig geen probleem hoor:

Kolom aantal komt niet overeen met value aantal.

Dus een kwestie van velden tellen en de waardes in de value.
 
Jan R

Jan R

04/12/2021 16:17:43
Quote Anchor link
Je gaat toch niet 2X het wachtwoord opslaan????
Laat staan ongecodeerd.
ps de usernaam zit niet in de waarden
 
Ed Jeurissen

Ed Jeurissen

04/12/2021 16:29:35
Quote Anchor link
Ja klopt dat moet nog gehashed worden, maar een slot op een deur maak je ook pas als het huis af is. En ik zet dit allemaal niet online!
 
Jan R

Jan R

04/12/2021 16:47:19
Quote Anchor link
Met achteraf loop je het risico om 1tje te vergeten. Ik doe dat niet meer en toch ben ik er deze week in geslaagd om er toch 1 niet te doen.

Van uitstel komt afstel.
 
Ed Jeurissen

Ed Jeurissen

04/12/2021 16:50:20
Quote Anchor link
Hoi Jan Raar dat je dat vergeet. Daar kom je achter als je het huis verlaat en het opslot wil doen. Kan je er ook een bordje bijzetten: In dit huis alles gratis af te halen!


Toevoeging op 04/12/2021 16:55:49:

Hoi Arien

Dit zijn er 13 (kolommen). Dier worden in db ook aangemaakt!
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    <div class="form-group">
            <label>ID</label>
            <input type="text" class="form-control" placeholder ="Enter your name" name= "id" autocomplete="off" required>
        </div>
    
        <div class="form-group">
            <label>Voornaam</label>
            <input type="text" class="form-control" placeholder ="Enter your name" name= "voornaam" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>Achternaam</label>
            <input type="text" class="form-control" placeholder ="Enter your achternaam" name= "achternaam" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>email</label>
            <input type="email" class="form-control" placeholder ="Enter your email" name= "email" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>telefoonnummer</label>
            <input type="text" class="form-control" placeholder ="Enter your password" name= "telefoonnummer" autocomplete="off" required>
        </div>
        <div class="form-group">
            <label>adres</label>
            <input type="text" class="form-control" placeholder ="Enter your name" name= "adres" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>postcode</label>
            <input type="text" class="form-control" placeholder ="Enter your postcode" name= "postcode" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>woonplaats</label>
            <input type="text" class="form-control" placeholder ="Enter your woonplaats" name= "woonplaats" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>username</label>
            <input type="text" class="form-control" placeholder ="Enter your username" name= "username" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>password</label>
            <input type="password" class="form-control" placeholder ="Enter your password" name= "password1" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>password</label>
            <input type="password" class="form-control" placeholder ="Enter your password again" name= "password2" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>geslacht</label>
            <input type="text" class="form-control" placeholder ="Enter your geslacht" name= "geslacht" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>geboortedatum</label>
            <input type="text" class="form-control" placeholder ="Enter your geboortedatum" name= "geboortedatum" autocomplete="off" required>
        </div>


        <button type="submit" class="btn btn-primary" name= "submit" >Submit</button>
    </form>

    </div>


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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    <div class="form-group">
            <label>ID</label>
            <input type="text" class="form-control" placeholder ="Enter your name" name= "id" autocomplete="off" required>
        </div>
    
        <div class="form-group">
            <label>Voornaam</label>
            <input type="text" class="form-control" placeholder ="Enter your name" name= "voornaam" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>Achternaam</label>
            <input type="text" class="form-control" placeholder ="Enter your achternaam" name= "achternaam" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>email</label>
            <input type="email" class="form-control" placeholder ="Enter your email" name= "email" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>telefoonnummer</label>
            <input type="text" class="form-control" placeholder ="Enter your password" name= "telefoonnummer" autocomplete="off" required>
        </div>
        <div class="form-group">
            <label>adres</label>
            <input type="text" class="form-control" placeholder ="Enter your name" name= "adres" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>postcode</label>
            <input type="text" class="form-control" placeholder ="Enter your postcode" name= "postcode" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>woonplaats</label>
            <input type="text" class="form-control" placeholder ="Enter your woonplaats" name= "woonplaats" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>username</label>
            <input type="text" class="form-control" placeholder ="Enter your username" name= "username" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>password</label>
            <input type="password" class="form-control" placeholder ="Enter your password" name= "password1" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>password</label>
            <input type="password" class="form-control" placeholder ="Enter your password again" name= "password2" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>geslacht</label>
            <input type="text" class="form-control" placeholder ="Enter your geslacht" name= "geslacht" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label>geboortedatum</label>
            <input type="text" class="form-control" placeholder ="Enter your geboortedatum" name= "geboortedatum" autocomplete="off" required>
        </div>


        <button type="submit" class="btn btn-primary" name= "submit" >Submit</button>
    </form>

    </div>


Dit zijn er 12, maar ID is A_I. Dus die hoef je niet op te geven (wordt vanzelf gemaakt, en is ook niet wijzigbaar)

Hoe moet het dan??


Plaatje van de tabel
Modedit: Link verwijderd vanwege persoonlijke details, gebruik dan overduidelijke dummy-accounts of blur het weg.

Toevoeging op 04/12/2021 17:08:46:

Nog een plaatje

https://ibb.co/XWr9tK3
Gewijzigd op 04/12/2021 18:16:25 door - Ariën -
 
- Ariën  -
Beheerder

- Ariën -

04/12/2021 18:08:25
Quote Anchor link
Velden die je niet invoert, die hoef je ook niet te benoemen.
 



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.