Well, I didn’t completely fix your form, but it’s much closer. Someone with more experience in PDO will be able to help with the rest. There’s definitely something wrong with the SELECT query.
Anyways, here’s your html file:
(Fixed the indentations and other junk)
[code]
Search Engine
Search Engine
Search by Name
Search by License, Certification, or Training
Aerial Work Platforms
Asbestos Awareness
Crane Operator
First Aid
Forklift Operator
Lead Awareness
OSHA 10
OSHA 30
Personal Protection Equipment Training
MUST 18 Modules
[/code]
Here’s your PHP:
[php]<?php
require_once (‘mysql.php’);
try{
// connect to MySQL
$db=new MySQL(array(‘host’=>‘localhost’,‘user’=>’’,‘password’=>’’,‘database’=>’’));
if(isset($_POST[‘searchterm’]) { $searchterm = $db->escapeString($_POST[‘searchterm’]); }
if(isset($_POST[‘check_list’]) && is_array($_POST[‘check_list’])){ $check = $_POST[‘check_list’]; }
foreach($_POST[‘check_list’] as $check) {
$workerquery = “SELECT firstname, lastname, asbestos FROM users WHERE (”.$searchterm." > ‘’ AND (firstname,lastname)=:searchterm) OR (:check > ‘’ AND asbestos=:check)";
$result=$db->$workerquery;
if(!$result->countRows()){
echo ‘
No results were found. Go back and try a new search.
’;
} else {
echo ‘
Your search criteria returned ‘.$result->countRows().’ results.
’;
while($row=$result->fetchRow()){
echo ‘
’
‘First Name:’.$row[‘firstname’].
‘Last Name:’.$row[‘lastname’].
‘Asbestos:’.$row[‘asbestos’].
‘
’;
}
echo ‘
’;
}
}
catch(Exception $e){
echo $e->getMessage();
exit();
}
?>[/php]
Your foreach line is messed up as well:
[php]foreach($_POST[‘check_list’] as $check) {[/php]
$check = $_POST[‘check_list’] as defined earlier in your code. This line won’t work.
Also, I changed how $check is created. You created $check first then did an isset statement. It should be the other way around. So, I changed it to this:
[php]if(isset($_POST[‘check_list’]) && is_array($_POST[‘check_list’])){ $check = $_POST[‘check_list’]; }[/php]
Now, $check is being properly “checked”
Someone else with more knowledge of PDO will need to finish it. I fixed what I saw, but the rest is beyond me.