I am currently trying to complete a project in which specifications should use the search form to search through the packaging database. The database has many variables: from sizes, names, types and meat. I need to create a search form in which users can search for several different queries (for example, search for a cover tray of 50 cm length).
I've been trying all day to create some PHP code that could look up information in a test database that I created. I had a lot of errors: from mysql_fetch_array errors, logical errors, and now my last error is that my table does not seem to exist. Although I can enter data into it (html and php pages where I can enter data), I do not know what causes this, and I started again several times.
Can someone give me some idea or advice on what I need to do now? Here are just my little tests at the moment, before I go to the SQL database of real sites.
Database creation:
<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 that I use to try to collect information from the database (I have rewritten this several times, this code also displays "table.liam does not 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>
If anyone knows or can help me, I would be very grateful! Thanks in advance.
html sql database php mysql
Liam Horizon
source share