There are at least two errors in your PHP code:
Retrieve values in the superglobal $_POST
without checking whether the request handled by the server is a POST. That is, when you access the page via the browser, it sends a GET request to the server, so the values in $_POST
do not exist, generating an error. If you did not see the error messages, it's possibly because your server is configured for it - which is bad in a development environment: error messages are the developer's best friends, as they tell us what's wrong and pulp time. To get around this, just check the HTTP request method:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
include_once("conexao.php");
$nome = $_POST['nome'];
$email = $_POST['email'];
$senha = $_POST['senha'];
...
}
Your SQL query is structured in the wrong way for two reasons:
- You are using brackets (
[]
) instead of braces ( {}
);
- You are not inserting the quotation marks correctly into the values;
The correct form of the query would be:
$sql = "INSERT INTO 'usuarios' ('nome', 'email', 'senha') VALUES ('{$nome}', '{$email}', '{$senha}')";