0

I have this warning, how do I fix it?

Notice: Trying to access array offset on value of type bool in C:\Program Files\Ampps\www\NodeMCU\read tag user data.php on line 17

Code

require 'database.php';
$id = null;
if ( !empty($_GET['id'])) {
    $id = $_REQUEST['id'];
}
 
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM tb_nodemcu where id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
$data = $q->fetch(PDO::FETCH_ASSOC);
Database::disconnect();

$msg = null;
if (null==$data['name']) {
    $msg = "The ID of your Card / KeyChain is not registered !!!";
    $data['id']=$id;
    $data['name']="--------";
    $data['gender']="--------";
    $data['email']="--------";
    $data['mobile']="--------";
} else {
    $msg = null;
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • [**Please Never** post images of code, data or error messages](https://meta.stackoverflow.com/a/285557/2310830). Please edit your question and include copy/paste the text into the question, formatted. This is so that we can try to reproduce the problem without having to re-type everything, and your question can be properly indexed or read by screen readers. – RiggsFolly Mar 22 '22 at 16:44
  • Either you query failed, or there is no column called `name` in your table – RiggsFolly Mar 22 '22 at 16:46
  • Interesting logic, why test the existance of one thing and then retrieve data from another? `if ( !empty($_GET['id'])) { $id = $_REQUEST['id']; }` – RiggsFolly Mar 22 '22 at 16:49

0 Answers0