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?
– Willian
// create connection $Conn = mysqli_connect("servername", "username", "password", "dbname"); // check connection if (!$Conn) { die("Connection failed: " . mysqli_connect_error(); }
– Lucas Tadeu
Unknown MySQL server host
.. did not find the server on this IP/Port– Cleber Griff
@Clebergriff So there is no syntax error?
– Lucas Tadeu
Uai man vc have to put your users correct ta error in connect.... your development location and online?
– Willian
@Willian is online man, in fact when I was doing via xwamp was working, now that I went up to hosting this error
– Lucas Tadeu
$servername = "#"; $username = "#"; $password = "#"; $dbname = "#"; // create connection $Conn = mysqli_connect("servername", "username", "password", "dbname"); // check connection if (!$Conn) { die("Connection failed: " . mysqli_connect_error(); }
– Lucas Tadeu
I put the # not to show the bad data look there
– Lucas Tadeu
Have you switched the host to localhost? Since you are hosting, it is no longer the url, it is already local
– Woton Sampaio
@Wotonsampaio Yes
– Lucas Tadeu
Wouldn’t that be it? Error? " {$servername}" No variable
– Willian
@Willian No =x
– Lucas Tadeu
guy tries to pass it to Pdo
– Willian
$Conn = mysqli_connect("localhost", "root", "password", "dbname"); try this simple
– Willian