I have to create 6 queries and print them to an HTML document. 5 out of the 6 variable work perfectly and display the results, I use the same syntax for all 6 variables, but the 4th variable is not working despite checking all the syntax and not having any errors in my IDE. I am getting these two errors in the browser:
Notice: Undefined variable: containsNumbers in C:\xampp\htdocs\scripts\Project3\template.html.php on line 38
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\scripts\Project3\template.html.php on line 38
I've already gone through all the code to make sure all spelling is good and that the syntax matches specifically. I feel like the problem I'm having is with my for each loop.
Here is the php snippet
//Try catch statment with query to check if the first name contains numbers.
try{
$sql = "SELECT * FROM employees WHERE first_name REGEXP '[0-9]' 'results'";
$result = $pdo->query($sql);
} catch (PDOException $e){
$output = "Error selecting id" . $e->getMessage();
include 'output.html.php';
exit();
}
// For each loop used to process results one at a time
foreach ($result as $row){
//Stores each results of the query in an array called containsNum
$containsNumbers[] = $row['results'];
}
And here is the HTML snippet
<h1>Here are the results of any names with numbers in them.</h1>
<div class="wrapper">
<div id="section--4" class="section">
<?php foreach ($containsNumbers as $employee): ?>
<div><?php echo htmlspecialchars($employee, ENT_QUOTES, 'UTF-8');?></div>
<?php endforeach; ?>
</div>
</div>
I expect the result to print any names that have numbers in them, but I am just getting errors.
EDIT****: to add some context this is the question I am trying to answer: 4. Write a query to check if the first_name fields of the employees table contains numbers.