Problem when trying to link bd to index

Asked

Viewed 21 times

0

I created an html file just to learn a little bit. I also created a css. Only, when trying to link a database so that you can register with e-mail and password on the site, I could not do, because always returns an error. This is the HTML file:

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <title>Gestão em O.B</title>
    <link rel="stylesheet" href="blz.css"> <!direcionamento para o arquivo css>
</head>

<body>
    <form class="formato" action="recebe.php" method="post"> <!formato da tela de login>

        <div class="telalogin"> <!tela de login>
            <img src="shen.jpg" width=150px height=150px> <!imagem>
            <h2 class="titulo"> Acesso ao Sistema </h2> <!titulo>
            <h3 class="subtitulo">Gestão para Operações Binárias</h3> <!subtitulo>

        <div class="email"> <!classe email>
            <label>Email</label> <!legenda do formulário e-mail>
            <input type="email" name="email" placeholder="Digite seu email" required></input> <!local para colocar o e-mail>
        </div>

        <div class="senha"> <!classe senha>
            <label>Senha</label> <!legenda do formulario senha>
            <input type="password" name="senha" placeholder="Digite sua senha" required></input> <!local para colocar a senha>
        </div>

        <div class="mantersessao"> <!classe do botão de manter sessao ativa>
            <input type="checkbox"></input> <!caixa de marcacao lembre-me>
            <label>Lembre-me</label> <!legenda da caixa lembre-me>
        </div>

        <div class="botao">
            <button type="submit">ACESSAR</button>
        </div>


        </div> <!final da tela inicial>

</form>
</body>
</html>


This is the file that receives the data from the index.html:

<?php

require_once("connection/conexao.php");

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


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

if(!$result) {
    echo("Ocorreu um erro durante a inserção na tabela!");
} else {
    echo("Dados inseridos com sucesso!");
}

?>

This is the PHPMYADMIN connection file:


<?php

$con = mysqli_connect("localhost", "root", "");
$db = mysqli_select_db("gestao_ob", $con);

if(!$con) {
    die("Não foi possível conectar ao banco de dados; " . mysql_error());
}

?>

I’m a beginner in this part, I spent all afternoon trying, but I couldn’t.

The error is as follows:


Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\Users\-\Desktop\xamp\htdocs\csti\connection\conexao.php on line 4

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\Users\-\Desktop\xamp\htdocs\csti\recebe.php on line 10
Ocorreu um erro durante a inserção na tabela!

  • You are passing the parameters in the wrong order. The correct one would be mysqli_select_db($con, nome_do_banco).

  • Hello. Thank you for answering. I did this fix, now there is only the following error in the receive file.php: Warning: mysqli_query() expects at least 2 Parameters, 1 Given in C: Users-Desktop xamp htdocs csti gets.php on line 10 An error occurred while inserting into the table! the line 10 is this: $result = mysqli_query($sql);

  • You need to pass 2 parameters to the mysqli_query function. One would be the connection and the other the Query. Friend suggest q read the documentation of each method and try to at least understand the error message.

  • Really friend, I had heard about it. I put the 2° parameter and now the error has stopped. Just informs An error occurred while inserting in the table!. I’ll try to fix that mistake!

  • Remove the comma at the end of your Insert query, right after the password variable. $sql = "INSERT INTO usuario (email, senha) VALUES ('$email', '$password')";

  • Thanks brother, now it worked. Maybe in one of the attempts I forgot this comma there. Thank you very much! I tried all afternoon, and you saved me kkkkkk. Vaaleeeeeeeeeeeeu

Show 1 more comment
No answers

Browser other questions tagged

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