How to know if the database connection is correct PHP

Asked

Viewed 117 times

0

I’m 16 hours away trying to make a database connection work and I’m not getting it, I don’t know what I’m doing wrong, I’m currently using shaman, and I’m working for a client who needs to access the database in a relatively simple way, and that connection doesn’t unravel.

    $_POST['botao'];
$nivel = $_POST['depressao'];


$servername = "localhost";
echo $servername;
$database = "test";
echo $database;
$username = "root";
echo $username;
$password = ""; 
echo $password;

$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection

$query = "insert into triste (depressao) values ({$nivel})";

mysqli_query($conn, $query);
mysqli_close();

?>


<form action="conexao.php">
  <input name="depressao" />
  <button type="submit" name="botao"></button>
</form

>

Yes I changed the database to a table and a test db, to force some errors out of production, and the database just doesn’t connect, I’ve tried to make this connection in several ways, I don’t know what to do, I’m almost changing to Node.js. that although I do not know much, at least I know in Js, I know la to really lost. who can give me a light I am grateful!

  • 1

    if (!$conn) {&#xA; printf("Connect failed: %s\n", mysqli_connect_error());&#xA; exit(); } .. View documentation

  • If you try to connect with these command line parameters what happens?

  • Nothing happens, he simply ignores all the php code that is written. and doing some testing today, I discovered that this code is being commented on the console. The code is being commented whole with comment in the generated html page <!---->

1 answer

0


After a long time, looking for how to solve this problem, and discovered, that the fault was not in the code itself, but in a file, .htaccess that was preventing the server from finding the path to the PHP folder. I thank those who tried to help

Browser other questions tagged

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