Connecting php with mysql

0

I made a login and registration system however I have a problem, every time I finish filling out the form and click send it gives me an error like this

  

"Warning: mysqli_connect (): (HY000 / 2005): Unknown MySQL server host   '?' (0) in /home/marmo504/interestrar.liferedes.com.br/insert.php on   line 19 Connection failed: Unknown MySQL server host '?' (0) "

I did everything and could not solve, could you help me?

Below the source code:

<?php

  $servername = "#.br";
  $username = "#";
  $password = "#";
  $dbname = "#";

  // criar conexão
  $conn = mysqli_connect("servername", "username", "password",  "dbname");

  // checar conexão
  if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
  }

  $sql = "SELECT * FROM clientes";
  $result = mysqli_query($conn, $sql);

  if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
      echo "- ID: " . $row["id"]. "<br> - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br> - E-mail: " . $row["email"] . "<br> - Data de Nascimento: " . $row["dat_nasc"] . "<br> - Cidade: " . $row["cidade"] . "<br><br>";
    }
  } else {
    echo "0 results";
  }

 ?>

  <form action="#" method="link" style="margin-left:500px">
  <input type="submit" value="Voltar">
  </form>
    
asked by anonymous 05.07.2018 / 16:19

2 answers

0

The error points out that your server does not exist, you are passing the server as a servername.

The server we use for testing is localhost or ip 127.0.0.1

Example: Your server being localhost. The user of your database is root. The root password is 12345. And the name of your database is stock.

// Your connection would look like this

$ conn = mysqli_connect ("localhost", "root", "12345", "stock");

Please check if it works.

Reference: link

    
05.07.2018 / 17:21
-1

Friend, your code is kind of strange, I believe that in this part you should pass the variables $servername, $username, $password, $dbname . right?

would look like this:

$conn = mysqli_connect($servername, $username, $password,  $dbname);

Of course, fill these variables with the actual values of the Server. Example:

$servername = "localhost";

$username = "root";

$password = "123456";

$dbname = "lojavirtual";

I hope I have helped!

    
05.07.2018 / 16:33