PRG Pattern
The first thing that caught my eye was not related to your actual issue, but does play a part in debugging. What caught my eye was
if (isset($_POST['search_button'])){
after HTML output was already started. Rule of thumb, POST variables should be worked with at the top, and always redirected (except ajax). Check out the Post-Redirect-Get pattern.
However, in this case you should be using GET because you aren’t changing data, just reading specific data.
Which leads me to the debugging step
Separate Logic and Presentation
Perform all your logic first, and then when that is all done, close out php and write your html (presentation), using php only for templating (loops, filling in variables, minor presentation conditionals)
This is extremely helpful when debugging, because you don’t have to dig through extraneous html code.
So your code could be reordered to be like this:
<?php
if (isset($_GET['search_button'])){
require_once "/home/users/web/b1240/dom.heather93124/public_html/resources/config.php";
$fName = $_GET['fName'];
$lName = $_GET['lName'];
// more code here
}
// any other code here
?>
<html>
<!— and so forth —>
Prepared Statements
The time to learn better security is now. This query is wide open to sql injection. Never, never, never put a raw variable into a query. You should be using prepared statements, where the user data is treated separately from the query. This example assumes you have a PDO connection $pdo
.
$stmt = $pdo->prepare("SELECT * FROM Customers Where FirstName LIKE ? AND LastName LIKE ?");
$stmt->execute(
[
$_GET['fName'],
$_GET['lName']
]
);
// iterate through results with $stmt->fetch()
Incorporating this change will fix the error in your code. ($search->fetch...
is an error)
Wrapping It Up
<?php
if (isset($_GET['search_button'])) {
require_once "/home/users/web/b1240/dom.heather93124/public_html/resources/config.php";
$stmt = $pdo->prepare("SELECT * FROM Customers WHERE FirstName = ? AND LastName = ?");
$stmt->execute(
[
$_GET['fName'],
$_GET['lName']
]
);
}
?>
<HTML>
... snip ...
<div class="form-popup" id="newApp">
<form method="get" class="form-container">
<h1>New Appointment</h1>
<label for="emp_select"><b>Select Employee</b></label>
<select id = "emp_select" name="emp_select0">
<?php
include "/home/users/web/b1240/dom.heather93124/public_html/resources/employee.php";
?>
</select><br>
<input type="text" name="fName" id="fName" placeholder="First name">
<input type="text" name="lName" id="lName" placeholder="Last name"><br>
<input type="button" class = "btn" value="Search" name="search_button"></button><br>
<select id = "custSelect" name="custSelect0">
<?php while($row = $stmt->fetchObject()): ?>
<option value="<?= $row->CustId ?>"><?= $row->fName ?> <?= $row->lName ?></option>
<?php endwhile; ?>
... snip ...
Note that this is not tested, you may have to adjust the pdo options to your taste.