Database query failed. Cant find the mistake | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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; ?>

9th Nov 2017, 1:00 PM
TheGamingChris
TheGamingChris - avatar
2 Respostas
+ 10
Use $conn as first argument of mysqli_query $resultĀ =Ā mysqli_query($conn, "SELECT name FROM links WHERE id =1");
9th Nov 2017, 1:27 PM
Shamima Yasmin
Shamima Yasmin - avatar
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>"; } }
9th Nov 2017, 2:11 PM
TheGamingChris
TheGamingChris - avatar