I am beginner in PHP and I am trying to figure out how to link a form to a PHP script.
Basically, I am creating a search bar where users can search the database for employee details based on their ID. The script would then retrieve the results from the database based on the ID.
Code:
<form action="results.php" method="get">
Employee ID: <input type="text" name="name"><input type="submit">
</form>
<?php
// connect to the mysql database server
$db = new PDO('mysql:host=localhost:3306;dbname=db_test14;charset=utf8', 'root', 'password');
// Prepare the statement (the basic outline of your query)
$st = $db->prepare('SELECT * from techsols_employee WHERE id = ?');
// Actually execute the query, putting in your id
$st->execute(array($employee_id));
// Get the actual employee details out of the result
$employee = $st->fetch();
?>
Would appreciate some help on this.