PHP ERROR - On the Database Connection

Asked

Viewed 25 times

0

Error ao tentar "conectar"

Connection to phpmyadmin HOST (n code wanted to go): inserir a descrição da imagem aqui

connection code to send to the databank:

 <?php

include_once("conexao.php");

$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
$email = $_POST['email'];

$sql = "INSERT INTO usuario (usuario, senha, email ) VALUES ('$usuario', '$senha', '$email')";
$salvar = mysqli_query($conexao, $sql);

mysqli_close($conexao);

?>

Totally new to this subject, any help would be greatly appreciated.

  • The problem does not appear to be in the connection to the database, but rather that you are running the code without sending the data in the request via POST. The errors that appear are that the indexes you are searching for in the POST associative array do not exist.

  • Actually as reported in the comment above, it does not display database connection error (even because you stop running with the snippet or die ('Não foi possível conectar'); and that he was unable to identify the index variables $usuario = $_POST['usuario']; $senha = $_POST['senha']; $email = $_POST['email']; . That is, you are not getting the value of these variables or there is some problem in trying to capture these data that are apparently being sent. I recommend to post the fron-end code from where you send this data.

1 answer

0

Apparently your HTML is not sending the data. Check that the tag form has the attribute method with the value POST and ensure that within the form there are tags input or select with their respective values.

Example

<form action="processa.php" method="POST">
     <strong>Usuário</strong> <input type="text" name="usuario" required /><br />
     <strong>Senha</strong> <input type="password" name="senha" required /><br />
     <strong>Email</strong> <input type="email" name="email" required /><br />
     <button type="submit">Salvar Dados</button>
</form>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.