Click here to Skip to main content
15,068,929 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
connected Successfully
Warning: Attempt to read property "num_rows" on bool in C:\xmamp\htdocs\html1\tt.php on line 19
0 results


this is my error and i dont know what is the wrong thing

<?php
// set connection variables
$Host_name = "localhost";
$db_user ="root";
$db_password="";
$db_name = "rmap";
// connection to server & database
$conn =new mysqli($Host_name,$db_user ,$db_password, $db_name,);
  // check connection
  if ($conn->connect_error) {
    die('Connect Error: ' . $conn->connect_error);
}
   
   echo "connected Successfully";
  
$sql = "SELECT Forward,Left,Right,Backward,Stop FROM mymap";
$result = mysqli_query($conn, $sql);

if ($result->num_rows > 0){
  // output data of each row
  while(($row = $result->fetch_assoc()) !== null) {
    echo "Forward: " . $row["Forward"]. " - Left: " . $row["Left"]. "Righ: " . $row["Right"]."Backward: " . $row["Backward"]."Stop: " . $row["Stop"]."<br>";
} }else{
  echo "0 results";
}
$conn->close();
?>


What I have tried:

i tried many thing but nothing work
Posted
Updated 30-Jun-21 22:29pm

1 solution

Read the documentation:

Returns false on failure. For successful queries which produce a result set, such as SELECT, SHOW, DESCRIBE or EXPLAIN, mysqli_query() will return a mysqli_result object.
Since your query is a SELECT, and the return value is a bool, that means your query failed.

Assuming the table and column names are correct, the most likely cause is that you've used a "reserved word" as a column name:
MySQL :: MySQL 8.0 Reference Manual :: 9.3 Keywords and Reserved Words[^]

Left, Right, and Stop are all listed as reserved words. You will need to quote the names in order to select them.
SQL
SELECT Forward, `Left`, `Right`, Backward, `Stop` FROM mymap
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900