Neew help to send data to my database mysql xampp


here is my process.php file

$username = $_POST['name'];
$password = $_POST['password'];

if(!empty($username) || !empty($password)){
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "tut";

$conn = new mysqli($servername, $username, $password, $dbname);
    die ('connect Error('. mysqli_connect_error().')'. mysqli_connect_error());
}else {
    $SELECT = "SELECT username From register Where username = ? Limit 1";
    $INSERT = "INSERT Into register (username, password) values(?, ?)";

//prepare statement
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $username);
$rnum = $stmt->num_rows;

if ($rnum==0){

    $stmt = $conn->prepare($INSERT);
    $stmt->bind_param("ss", $username, $password);
    echo "New record inserted succesfully";
    echo "someone has already used this username";


    echo "All fields are required";


and here is my index.php

    require "header.php"

    <button action="process.php" method="POST">
        Klicka för att lägga in en produkt
    <form action="process.php" method="POST">
        <input type="text" name="name" placeholder="name">
        <input type="password" name="password" placeholder="password">
        <input type="submit">

    require "footer.php"

The whole logic is off. You don’t check for a username first. Set a unique constraint on the username column, attempt the insert and catch the duplicate error if any. Do not create variables for nothing. Do not output internal system errors to the user. I would also recommend you use PDO.


FYI: The limit one is pointless. There should only every be one unique username, therefore there will always only be one result.


You have a thread on this forum 9 days ago for a registration form and form processing code - Help with an error in my signup form?

I recommend that you reread (translating as necessary using google translator) the detailed reply you got. The forum members are not going to repeatedly look at code that contains the same problems you have already been made aware of.

There’s a new problem in the above code. You are reusing the $username and $password variables for two different things, which will prevent your code doing anything useful. If you are not aware from one point in your to code to few lines later what your variables are and what you are using them for, you won’t be able to program.

Also, your - if(!empty($username) || !empty($password)){ logic is wrong. You would want to use && (and) so that you only run the rest of the form processing code if both variables are not empty.