I have a page which uses the PDO method to pull results from a database.
I tried adding a search form and everything looks good.
But when I submit the form I get
Notice : Undefined variable: pdo in C:\xampp\htdocs\DCT\2\racks\index.php on line 73
Heres the PHP which im using
if(isset($_GET['Search'])) {
$search = strtolower($_GET['Search']);
preg_replace("#[^0-9a-z]#i","",$search);
$query = 'SELECT rack_id,title,room_id,row,bay
FROM racks
WHERE title LIKE "%'.$search.'%"';
$result2 = $pdo->query($query);
}
The pdo variable seems to work fine at the beginning
I think what @benanamen means is to show all the code between where it works successfully, and where it gives the error.
Does your search go through the code that defines the $pdo instance, or is that inside some other if() clause? Some more details on the structure of the code would be useful. Either it doesn’t define it in the first place, or it is clearing it. Just seeing the individual code snippets doesn’t allow anyone to see where that is happening. On the face of it, there’s nothing wrong with the second bit of code (presuming that’s where line 72 or 73 is, you don’t confirm that), so the problem must lie elsewhere.
@lurtnowski, it would be really helpful if you could put your app on Github. If you don’t want the code accessible to the world just make it a private repo and give access to it as you see fit. Having it on the repo will allow us to review the code as a whole. You have other issues besides what you posted about.