Why won't my form upload to my database? after submitting the databse is still empty

Quantum :

When I run this code it all goes fine. It gives me the message "New record inserted succesfully". The problem that I have is whenever I go to my databse to check it out. It's still empty, the information that I typed into the input boxes don't appear in my database. Just a blank database. I'm new to coding so please bear with me if I misused some words or don't quite understand my mistakes.

<!DOCTYPE HTML>
    <html>
    <head>
      <title>Sign Up Form</title>
      <meta charset="utf-8"> 
      <link rel="stylesheet" href="SignUp.css" type="text/css">
    </head>
    <body>
     <form action="insert.php" method="POST">
      <table>
      <tr>
        <td style="color:white">Username :</td>
        <td><input type="text" name="Username" required></td>
       </tr>
       <tr>
        <td style="color:white">voornaam :</td>
        <td><input type="text" name="Voornaam" required></td>
       </tr>
       <tr>
        <td style="color:white">Achternaam :</td>
        <td><input type="text" name="Achternaam" required></td>
       </tr>
       <tr>
        <td style="color:white">Wachtwoord :</td>
        <td><input type="password" name="Wachtwoord" required></td>
       </tr>
       <tr>
        <td style="color:white">Adres :</td>
        <td><input type="text" name="Adress" required></td>
       </tr> 
       <tr>
        <td style="color:white">Telefoon nummer :</td>
        <td>
         <select name="Telcode" required>
          <option selected hidden value="">Select Code</option>
          <option value="297">297</option>
         </select>
         <input type="phone" name="Telnummer" required>
        </td>
       </tr>
       <tr>
        <td><input type="submit" value="Submit"></td>
       </tr>
      </table>
     </form>
    </body>
    </html>


    <?php
    $Voornaam = $_POST['Voornaam'];
    $Username = $_POST['Username'];
    $Achternaam = $_POST['Achternaam'];
    $Wachtwoord = $_POST['Wachtwoord'];
    $Adress = $_POST['Adress'];
    $Telcode = $_POST['Telcode'];
    $Telnummer = $_POST['Telnummer'];
    if (!empty($Voornaam) || !empty($Achternaam) || !empty($Wachtwoord) || !empty($Adress) || !empty($Telcode) || !empty($Telnummer) || !empty($Username)) 
    {
        $host = "localhost";
        $dbUsername = "root";
        $dbPassword = "root"; 
        $dbname = "gevuldetomaat"; 



        $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
        if ($conn->connect_error)   {
         die("Connection failed: ". $conn->connect_error);
                                    } else      { 

         $SELECT = "SELECT Username From klant Where Username = ? Limit 1";
         $INSERT = "INSERT INTO klant (Wachtwoord, Achternaam, Voornaam, Telnummer, Telcode, Username, Adress) values(?, ?, ?, ?, ?, ?, ?)";


         $stmt = $conn->prepare($SELECT);
         $stmt->bind_param("s", $Username);
         $stmt->execute();
         $stmt->bind_result($Username);
         $stmt->store_result();
           $rnum = $stmt->num_rows; 
         if ($rnum==0) 
                    {
          $stmt->close();
          $stmt = $conn->prepare($INSERT);
          $stmt->bind_param("sssiiss", $Wachtwoord, $Achternaam, $Voornaam, $Telnummer, $Telcode, $Username, $Adress);
          $stmt->execute();
          echo "New record inserted sucessfully";
                    } 
         else   {
          echo "Someone already registered using this name";
                }
         $stmt->close();
         $conn->close();
                                                    }

    } 
    else    {
        echo "All fields are required";
        die();
            }
    ?>
Hunman :

It seems like you do run into that fork where the INSERT SQL runs, but you print the success message without checking whether it indeed was successfully inserted or not

After each mysqli_stmt::execute(), you should consider checking the mysqli_stmt::$errno variable to see if there was an error or not ($errno is short for "error number", if it's zero, there were no errors)

Something like this should tell you more about the error that happens:

if ($rnum == 0) {
    $stmt->close();
    $stmt = $conn->prepare($INSERT);
    $stmt->bind_param("sssiiss", $Wachtwoord, $Achternaam, $Voornaam, $Telnummer, $Telcode, $Username, $Adress);

    $stmt->execute(); // Run the INSERT statement
    if ($stmt->errno) { // Check for errors
        die("Error in inserting: " . $stmt->error); // Print last error
    } else { // No errors
        echo "New record inserted sucessfully"; // Success message
    }
} else {
    echo "Someone already registered using this name";
}

I did this only for the INSERT statement here, but you should consider doing something like this for the SELECT statement too

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why won't my other input values not insert to my database?

Why can't the database still not save the data with my current TypeConverter?

My database won't insert my record when i submit my form

The PHP linked to this form isn't submitting entries to my database

when write to the database,database is still empty after registering.how to store data in my database correctly?

Why won't my form add a new item to the list?

Why won't my Ruby app save instances to the database?

Why is my form not submitting data to update my database?

Why won't my div reveal itself after Ajax call?

Why does my form with empty upload form take so long? What could be the reason?

Why won't this insert into my database?

Why without using action my form still stores data into database

JavaScript: Why won't my form submit?

My form data won't post into my phpmyadmin database

PDO won't update my data in the database, why?

Why is my form not submitting or posting

Why is my javascript form not submitting?

Why isn't my form submitting

Why won't my image files upload in PHP?

My Django form data won't save to my database

Why won't my data go into my database?

In my spring login form url getting changed after submitting the form

Why won't my user input field reset after submitting?

How do I check users email isn't already in my database when submitting a form?

Why won't my button change state after adding a class?

Why won't my alerts work after my if statements?

why after calling the method my kivymd app won't close?

Why is my ipcMain returning an empty array after reading through a database?

After adding record to my database form is still filled with added info