database only saving the password [closed]

-1

This is my first post here, I've been following the forum for a long time but I never wanted to interact, today this will came along with a little problem ...

To learn html, css, php and etc ... from tutorials, after countless failures I just manage to accomplish what I want. I have the habit of watching several tutorials about the same time and after watching everyone decide which one to use, based on the divergence of information between them and in my intuition. Until it works, but something always happens wrong and then I start looking for content to solve. One of the problems that haunts me is that I do not know how to quote the mistake that has happened, like this one that is happening now. So I think here would be the best option.

The problem: '

<?php </br>
session_start();</br>
$_SESSION['message']  = '';

$mysqli = new mysqli('localhost','root','','accounts'); </br>

if ($_SERVER['REQUEST_METHOD'] == 'POST') { <br>
    if ($_POST['password'] == $_POST['confirmpassword']){ <br>
        $username = $mysqli->real_escape_string($_POST['username']); <br>
        $email = $mysqli->real_escape_string($_POST['email']); <br>
        $password = md5($_POST['password']);

        $sql = "INSERT INTO users (username, email, password) "
        . "VALUES ('$username', '$email', '$password')";
        //if the query
        if ($mysqli->query($sql) === true) {
            $_SESSION['message'] = "deu certo";
            header("location: welcome.php");
        }

        else {
            $_SESSION['message'] = "Usuario nao pode ser add";
            }
        }
    }
?>

Difficulty understanding this code tag, my god.

ThisisthetableIcreated:butwhenIgotocheckthedbitonlyhasthis:

This is my first question, if I did something wrong please tell me. Thanks!

    
asked by anonymous 14.11.2017 / 10:41

2 answers

1

Your problem is in the form that returns data via POST .

You have not put the name="username" tag in your input:

Current:

<input id="username" type="text" placeholder="Username" required autofocus>

Correct:

<input id="username" type="text" placeholder="Username" name="username" required autofocus>

<input id="email" type="email" placeholder="Valid Email" name="email" required autocomplete>

In addition:

Your password field is only with 10 caracteres .

Type md5 generates 32 caracteres .

Increase the field in your bank.

More on MD5: link

    
14.11.2017 / 10:51
-1

Come on, first get those <br/> from within PHP, if you want to use them put in a echo . To avoid problems with quotation marks etc in your SQL use {}:

$sql = "INSERT INTO users (username, email, password) VALUES ('{$username}', '{$email}', '{$password}')";

If you want to know if the data is really coming from one:

echo "<pre>";
print_r($_POST);
echo "</pre>";

So you will see the entire POST Array (), only then you will be able to understand where the problem comes from, whether it is in POST or not.

    
14.11.2017 / 11:05