$query = "SELECT COUNT (*) AS spo  FROM NAME_TABEL WHERE     
BEFORE_OURCE_OBAT = '1' AND ROOM = 'ORCHID' AND MONTH (DATE) = '$ month' ";
$row = sqlsrv_query($conn, $query);
$data  = sqlsrv_fetch_array($row);
$spo = $data['spo'];    

?> 

why an error appears after the program is run, please help ?

Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in  
C:\xampp\htdocs\siimut\name_tabel.php on line 140

Recommended Answers

All 2 Replies

If that is all your code then the $conn = sqlsrv_connect() is missing.

My guess is that the MySQLi connect function exists somewhere in the framework, etc., and not necessarily right above where a query call is being made.

Obviously here sqlsrv_query() is returning FALSE. This can happen because the SQL query is invalid. It can be invalid for a number of reasons:

  • NAME_TABEL doesn't exist or it's a typo and it's supposed to be NAME_TABLE
  • Table doesn't have columns BEFORE_OURCED_OBAT and ROOM
  • $ month is invalid ... it should be $month without a space, and you need to be properly escaping this variable to prevent SQL injections!
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.