So my problem is I do not understand why I am getting this error as I have used this code previously for a different task and it worked. Here is the sample code:
<?php
include('assets/php/sql/con.php');
if (isset($_GET['age'])) {
$AGE = $_GET['age'];
$GENDER = $_GET['gender'];
$results = DB::query('SELECT * FROM gift_db WHERE age =:age',array(':age' => $_GET['age']))[0]['age'];
// DB::query('SELECT * FROM gift_db WHERE age=:age', array(':age'=>$_GET['age']));
$allResults = "";
foreach ($results as $r) {
$allResults = $r;
}
}
?>
If anyone would be able to help out that would be amazing. Thanks :)
When use query function this function returned an array but you selected the first element of this array.
$results = DB::query('SELECT * FROM gift_db WHERE age =:age',array(':age' => $_GET['age']))[0]['age'];
Can you try with:
$results = DB::query('SELECT * FROM gift_db WHERE age =:age',array(':age' => (int) $AGE));
It's possible in your code insert any value on age.
PD:Sorry for my English
It seems like $AGE
is coming as a string, not an integer, so can you please try like below:-
$results = DB::query('SELECT * FROM gift_db WHERE age =:age',array(':age' => (int) $AGE));