I am working on a function where the specifications are to use a search form to search through a packaging database. I wanted to create a search form where users can search using different searches.
Creation of database:
<body>
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE db_test", $con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_select_db("db_test", $con);
$sql = "CREATE TABLE Liam
(
Code varchar (30),
Description varchar (30),
Category varchar (30),
CutSize varchar (30),
)";
mysql_query($sql, $con);
mysql_close($con);
?>
</body>
HTML search form page:
<body>
<form action="form.php" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
The PHP code I am using to attempt to gather info from the database (I have rewritten this a few times, this code also displays the "table.liam doesn't exist")
<body>
<?php
$con = mysql_connect ("localhost", "root", "");
mysql_select_db ("db_test", $con);
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
$sql = mysql_query("SELECT * FROM Liam WHERE Description LIKE '%term%'") or die
(mysql_error());
while ($row = mysql_fetch_array($sql)){
echo 'Primary key: ' .$row['PRIMARYKEY'];
echo '<br /> Code: ' .$row['Code'];
echo '<br /> Description: '.$row['Description'];
echo '<br /> Category: '.$row['Category'];
echo '<br /> Cut Size: '.$row['CutSize'];
}
mysql_close($con)
?>
</body>
Can someone give me some idea or a solution to do this?