Creating a search form in PHP to search a database?

Breamspresque

New Member
I am currently trying to complete a project where the specifications are to use a search form to search through a packaging database. The database has lots of variables ranging from Sizes, names, types and meats. I need to create a search form where users can search using a number of different searches (such as searching for a lid tray that is 50 cm long). I have spent all day trying to create some PHP code that can search for info within a test database I created. I have had numerous amounts of errors ranging from mysql_fetch_array errors, boolean errors and now currently my latest error is that my table doesn't seem to exist. Although i can enter data into it (html and php pages where I can enter data), I don't know what is causing this and I have started again a few times now. Can anyone give me some idea or tips of what I am going to have to do currently? Here is just my small tests at the moment before I move onto the actual sites SQL database. Creation of database: \[code\] <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>\[/code\]HTML search form page: \[code\]<body> <form action="form.php" method="post"> Search: <input type="text" name="term" /><br /> <input type="submit" name="submit" value="http://stackoverflow.com/questions/12747650/Submit" /> </form></body>\[/code\]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")\[code\] <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>\[/code\]If anyone has any insight or can help me with this I would be very grateful! Thanks in advance.
 
Back
Top