0
Database query failed. Cant find the mistake
Hey, can someone help me? It connected to the database successfully, but then it is create the following error: Fatal error: Uncaught Error: Call to undefined function mysqli_query() in [my path]:17 This is the Code: <?php $servername = "my_servername"; $username = "my_username"; $password = "my_password"; $base = "my_database"; // Create connection $conn = new mysqli($servername, $username, $password, $base); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?> <?php $result = mysqli_query("SELECT name FROM links WHERE id =1"); echo $result; ?>
2 ответов
+ 10
Use $conn as first argument of mysqli_query
$result = mysqli_query($conn, "SELECT name FROM links WHERE id =1");
0
I have found the mistake.
This is the right Code:
if ($result = mysqli_query($conn, "SELECT name FROM links")) {
while($row = $result->fetch_assoc()) {
echo "{$row['name']} <br><br>";
}
}