You folks were so helpful back in 2019 when I needed help with something similar that I’m trying again. The 2019 solution has worked for years but now I’m trying to use the search field to populate the output from a form. I have looked at the “similar topics” here but none are what I’m looking for.
I’m working on an online dog show entry form. Instead of the user typing all their dog’s information into the form with the various classes they can enter, I’ve set it up so all the dog’s info is in a table named “dognames”. Then the classes they want to enter will go into the “entries” table, along with the dog info pulled from the search results.
I’ve been struggling with it for 3 days now and have a niggling feeling that I have the search form in the wrong place but no matter what I try, the data is not transferred over to the “entries” table. It throws up an error that the field RegNo (dog’s registration #) cannot be empty, so obviously the search data doesn’t make it to the form.
I’ve removed a LOT of non-pertinent info (such as the 20-odd classes which can be entered), leaving just one class - so the code isn’t miles long. Note that the search result is named RegNoSearch:
<body>
<form action="" method="post">Enter registration number:
<input type="text" name="RegNoSearch" title="Registration Number" size="12" maxlength="12" />
<input type="submit" value="Search"/>
</form> <br>
<?php
// adding the next three lines should display the error
// declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors' ,'1');
$servername = “ ”;
$username = “ ”;
$password = “ ”;
$dbname = " ";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$SearchRegNo = $_POST["RegNoSearch"]; // RegNoSearch = field name from above form
$sql = "SELECT * FROM dognames WHERE RegNo LIKE '$SearchRegNo'";
$result = $conn->query($sql);
echo '<pre>'; print_r($result);
if ($result->num_rows >0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<p class='left'><br>
Registration Number: ". $row["RegNo"].
"<br>Dog Name: ". $row["ConfTitles"]. " " . $row["DogName"]. " ". $row["FldTitles"].
"<br>Owner: ". $row["Owner"].
"</p>";
}
} else {
echo "<p class='center'><br>0 results";
}
}
?>
<p>Conformation Class:
<select name="ConfClass" title="Conformation Class">
<option value="" selected>No Entry</option>
<option value="6-9 Puppy">6-9 Puppy</option>
<option value="9-12 Puppy">9-12 Puppy</option>
</select></p>
<p>Owner-Handled Eligible?
<select name="OwnerHandled">
<option value="No" selected>No</option>
<option value="Yes">Yes</option>
</select>
</p>
<p>Clicking the button below will send your entry.</p>
<p class="center">
<input name="knlSubmit" type="submit" id="knlSubmit" value="SUBMIT ENTRY" />
</p>
</form>
<div id="footer">
<p class="small">© <?php
$thisYear = (int)date('Y');
echo $thisYear;?> Borzoi Club of America Inc. • Last updated <!-- #BeginDate format:Am1 -->February 10, 2024<!-- #EndDate --> • <a href="../sitemap.php" title="Sitemap for the BCOA website">SITEMAP</a> • <a href="../copyright.php">Copyright Policy</a>
</p>
</div> <!-- footer -->
</body>