Does not insert information into the database

1

Good afternoon, I'm trying to insert data into a database and I get the error message: "Could not register the user".

I'm using Xamp software, with both Apache and Mysql installed.

The code is as follows:

<head>

    <meta charset="UTF-8">
    <meta http-equiv="content-type">
    <title>Adicao Usuario Banco de Dados</title>

</head>

<body>

    <?php

    echo "<h1>ADICAO DE USUARIO</h1>";
    $conexao_bd = mysql_connect("localhost");

    if(!$conexao_bd) {

        echo "<p><b>Não foi possível conectar ao Banco de Dados</b></p>";
        echo mysql_error();
    }

    else {
          mysql_select_db("db_hotel",$conexao_bd);
          $retorno = mysql_query("INSERT INTO usuarios(Nome_Usuario,Senha_Acesso) VALUES('ADMIN','M45T3R')");
        if(!$retorno)
          echo "<h2>Nao foi possivel cadastrar o usuario!</h2>";
        else
          echo "<h2>Usuario cadastrado com sucesso!</h2>";
        }
    mysql_close($conexao_bd);

    ?>

</body>

If you can help me, thanks in advance ....

    
asked by anonymous 18.10.2018 / 17:10

1 answer

1

mysql_connect Opens a connection to a MySQL server. Try adding the user and password parameters. Example:

$conexao_bd = mysql_connect('localhost', 'usuario', 'senha');

As you are using xampp, you can check which user is linked to localhost, then we will check where to find the user and password.

Notethatinthisexampletheuseroflocalhostisrootandwedonothaveapassword.Thatis,theopeningcodeforconnectingtothebankwouldbe:

$conexao_bd=mysql_connect("localhost","root",""); //host, usuario, senha vazia
    
18.10.2018 / 18:08