Hi All,
I am pretty much a newbie. I have built a form on a page that points to ProcessForm.php (The form has just one text entry field).
At ProcessForm.php, I am trying to put the php code on the page that will take what was entered by the user and search a column within my MySQL database for matches/partial matches. The aim is to then display found matches on a HTML page, basically similar to the way Kelkoo would work when you search for a product.
Problem is that I can't seem to make it work. If anyone could point me in the right direction it would be much appreciated.
For reference I have included the code I have tried to date below;
<?php
/ Script name: processform.php
Description: Script that takes query from form and searches database.
*/
echo "<html>
<head>
<title>Results</title>
</head>
<body>";
foreach ($_GET as $UserQuery => $value)
{
echo "$UserQuery = $value<br>";
}
?>
<?php
$host="localhost";
$user="username";
$password="password";
$database = "DB_Name";
$connection = mysql_connect ($host,$user,$password)
or die ("Couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$query = "SELECT * FROM DB_Table WHERE Title='$UserQuery'";
$result = mysql_query($query)
or die ("Couldn't execute query.");
$row = mysql_fetch_array($result);
echo $result;
?>
</body>
</html>
Thanks in advance.
Paul