That would indicate that there is a capitalization difference between the actual column names and what the php code is using.
In a query, the column names are not case-sensitive. However, the letter-case that you SELECT determines the associative index names that php must use. When you use *, the letter-case is what the column definition is. When you listed out the columns, you probably used what you were using in the php code, and they therefore match. I recommend that you only use lower-case letters in identifiers so that you don’t need remember what letter-case you defined them as.
Here’s what the code would look like with the points that were made -
<?php
// 1) initialization,
// this example uses the much simpler and better designed PDO extension
require 'pdo_connection.php';
$errors = []; // array to hold user/validation errors
// 2) post method form processing,
// 3) get method business logic - get/produce data needed to display the page,
// detect (see php's null coalescing operator) and trim the input
$search = trim($_GET['search']??'');
// validate the input
if($search === '')
{
// you need to decide what to do if the input is not valid
// either setup and display an error message (which is what is shown here) or use a default value or action, such as matching all values (leave the WHERE term out of the query)
$errors['search'] = 'Please enter a search term';
}
else
{
// a query that can match more then one row needs an ORDER BY term so that the rows will be in a desired order
$sql = "SELECT date, tid, origin
FROM hst_workings
WHERE origin like ?
ORDER BY date
";
$stmt = $pdo->prepare($sql);
$stmt->execute([ "%$search%" ]);
$result = $stmt->fetchAll();
}
// 4) html document.
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Search example</title>
</head>
<body>
<?php
// display any errors
if(!empty($errors))
{
echo '<p>'.implode('<br>',$errors).'</p>';
}
?>
<form>
<label>Search <input type="text" name="search" value="<?=htmlentities($search)?>"></label><br>
<input type ="submit">
</form>
<?php
// produce the output
if(empty($result))
{
echo "<p>0 records</p>";
}
else
{
echo "<p>Your search found ".count($result)." records</p>";
foreach($result as $row)
{
// apply htmlentities to all elements in row
$row = array_map('htmlentities',$row);
echo $row["date"]." ".$row["tid"]." ".$row["origin"]."<br>";
}
}
?>
</body>
</html>
Here’s typical PDO connection code -
$DB_HOST = ''; // database host name or ip address
$DB_USER = ''; // database username
$DB_PASS = ''; // database password
$DB_NAME = ''; // database name
$DB_ENCODING = 'utf8mb4'; // db character encoding. set to match your database table's character set. note: utf8 is an alias of utf8mb3/utf8mb4
$options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // set the error mode to exceptions - this is the default setting now in php8+
PDO::ATTR_EMULATE_PREPARES => false, // run real prepared queries
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC // set default fetch mode to assoc
];
$pdo = new pdo("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=$DB_ENCODING",$DB_USER,$DB_PASS,$options);