php connection to mysql

Asked

Viewed 348 times

1

i made a system of Login and registration but I have a problem, every time I finish filling the form and I click to send it me an error like this

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

I’ve done everything and I couldn’t fix it, you could 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>
  • Cade the connection?

  • // create connection $Conn = mysqli_connect("servername", "username", "password", "dbname"); // check connection if (!$Conn) { die("Connection failed: " . mysqli_connect_error(); }

  • Unknown MySQL server host.. did not find the server on this IP/Port

  • @Clebergriff So there is no syntax error?

  • Uai man vc have to put your users correct ta error in connect.... your development location and online?

  • @Willian is online man, in fact when I was doing via xwamp was working, now that I went up to hosting this error

  • $servername = "#"; $username = "#"; $password = "#"; $dbname = "#"; // create connection $Conn = mysqli_connect("servername", "username", "password", "dbname"); // check connection if (!$Conn) { die("Connection failed: " . mysqli_connect_error(); }

  • I put the # not to show the bad data look there

  • Have you switched the host to localhost? Since you are hosting, it is no longer the url, it is already local

  • @Wotonsampaio Yes

  • Wouldn’t that be it? Error? " {$servername}" No variable

  • @Willian No =x

  • guy tries to pass it to Pdo

  • $Conn = mysqli_connect("localhost", "root", "password", "dbname"); try this simple

Show 9 more comments

2 answers

0

The mistake points out that his servidor does not exist, you are passing the servidor as servername.

The servidor that we use to test is the localhost or ip 127.0.0.1

Example: Your server being localhost.

The user from your database be root.

The password of the user root be it 12345. And the name of his banco de dados be it stockpile.

// Sua conexão ficaria assim

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

Please check if it resolves.

Reference

  • Continuous giving the same error

  • I saw in the comments above that you said site works and online does not. You can try servername uses ip instead of localhost. Take in your hosting the ip to see if it resolves.

-1

Friend, your code is a little 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);

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

$servername = "localhost";

$username = "root";

$password = "123456";

$dbname = "lojavirtual";

I hope I’ve helped!

  • I did what you said, it’s still the same =x

  • What you put in $servername?

  • I believe the problem is in this line! maybe the server/url you placed is unknown.

  • I put the following link "br638.hostgator.com.br", which is the host that the hosting passed me to use on the host

  • but on which host dns or sql?

  • know pq when you enter br638.hostgator.com.br was to redirect you pro phpmyadmin "usually"

  • So, but this url is the one that you enter the control panel isn’t? if it is, it won’t work at all! search in the control panel in the database menu, usually it is there the url

Show 2 more comments

Browser other questions tagged

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