0
votes

I already tested this Firebase Filtering data with PHP but im getting this error and i dont have any clue how to debug this

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://table.firebaseio.com/tbl_admin?orderBy=%22username%22&equalTo=%22admin%22&limitToFirst=1 resulted in a 400 Bad Request response: { "error" : "Index not defined, add \".indexOn\": \"username\", for path \"/tbl_admin\", to the rules" } in D:\Xampp\htdocs\firebase\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113 Stack trace: #0 D:\Xampp\htdocs\firebase\vendor\guzzlehttp\guzzle\src\Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 D:\Xampp\htdocs\firebase\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))

2 D:\Xampp\htdocs\firebase\vendor\guzzlehttp\promises\src\Promise.php(156):

GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 D:\Xampp\htdocs\firebase\vendor\guzzlehttp\promises\src\TaskQueue.php(47): GuzzleHttp\Prom in D:\Xampp\htdocs\firebase\vendor\kreait\firebase-php\src\Firebase\Exception\QueryException.php on line 28

how will i filter this on firebase as i have queried it on mysql like this:

SELECT * FROM tbl_admin WHERE username = 'admin'

A table structure on firebase

1
Inlined image so users don't have to navigate away from StackOverflowJames Coyle

1 Answers

1
votes

If you read the error message, you'll find that it says:

Index not defined, add ".indexOn": "username", for path "/tbl_admin", to the rules

You can add those rules by navigating to the Database Rules section in the Firebase Web Console of your project (https://console.firebase.google.com/project/_/database/_/rules should™ bring you there) and adding the index so that your rules look something like this:

{
    "rules": {
        ".read": false,
        ".write": false,
        "tbl_admin": {
          ".indexOn": ["username"]
        }
    }
}

The important part is the tbl_admin field, don't just copy and paste the snippet if you already have other settings in your rules ^^.

enter image description here