I am searching a table in my DB to return a tick if a name matches a $_GET['name'] variable that I have passed in the URL.
I want a tick displayed if the name exists and a cross if it does not.
The purpose is to populate a rota / timetable of availability.
The code I have so far;
<?php foreach($rota_sun as $rota_sunday): ?>
<?php if(strpos($rota_sunday['person_name'], $_GET['name']) !== false) { ?>
<span style="color:green; font-size:22px;"><i class="fa fa-check" aria-hidden="true"></i></span>
<?php } else { ?>
<span style="color:red; font-size:22px;"><i class="fa fa-times" aria-hidden="true"></i></span>
<?php } ?>
<?php endforeach; ?>
My code for the query is;
$query = "SELECT
rota_sunday.id AS rota_id,
rota_sunday.person_id,
rota_sunday.person_name
FROM rota_sunday WHERE rota_sunday.person_name = '$_GET['$name']'
";
try
{
$stmt = $conn->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$rota_sun = $stmt->fetchAll(PDO::FETCH_ASSOC);
My table contains three rows;
- id
- person_id
- person_name
Aucun commentaire:
Enregistrer un commentaire