-2

This is my current code for adding some additional information to a database table named klantinfo. This information is added after the user is logged in. At the login, the given username gets inserted into the login table, but also into the klantinfo table. This way I can compare the username in the database with the username in the session, so I can display the correct data for the logged in user.

if (!$error) {
    
    
    $stmt = $connect->prepare("
        INSERT INTO klantinfo (voornaam, achternaam, telefoonnummer, straat, straatnummer, stad, postcode) 
        VALUES(?, ?, ?, ?, ?, ?, ?)");
    
    $stmt->bind_param("sssssss", $voornaam, $achternaam, $telnr, $straat, $straatnummer, $stad, $postcode);
    
    if($stmt->execute()) {
        
        $success_message = "De registratie is gelukt. U kunt nu inloggen.";
        
    } else {
        
        $error_message = "Error. Probeer het later opnieuw.";
        
    }
}

However, this just inserts the values into a new row in the database table. I want it to specifically insert the values into the already existing row of the user (the one with the username already in it) thats currently in the session.

I already tried other queries, with no luck.

For example, I tried adding this to the query:

WHERE username_info='$user'

Nothing works!

Dharman
  • 30,962
  • 25
  • 85
  • 135
Larsm19
  • 3
  • 1
  • 3
    Refer back to your introductory SQL tutorials. If you want to change an existing row, you just use an `UPDATE` query, not an `INSERT` – ADyson Dec 27 '21 at 12:26
  • Already tried that. Didnt work either. – Larsm19 Dec 27 '21 at 12:38
  • 3
    Didn't work how, specifically? Show what you tried and explain what error or problems you had. You definitely need an `UPDATE` if you want to change a row. If you made a mistake when writing your `UPDATE` statement, that's a different issue, and to fix it we need to see the details. – ADyson Dec 27 '21 at 12:42

1 Answers1

0

You should use an UPDATE statement instead of an INSERT statement. UPDATE changes the values in the database without inserting a new row whereas INSERT adds another row to the database. You can refer here: UPDATE(docs)

INSERT(docs)

INSERT

UPDATE