Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a search form in PHP to search a database?
    primarykey
    data
    text
    <p>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). </p> <p>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. </p> <p>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. </p> <p><em>Creation of database:</em> </p> <pre><code> &lt;body&gt; &lt;?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); ?&gt; &lt;/body&gt; </code></pre> <p><em>HTML search form page:</em> </p> <pre><code>&lt;body&gt; &lt;form action="form.php" method="post"&gt; Search: &lt;input type="text" name="term" /&gt;&lt;br /&gt; &lt;input type="submit" name="submit" value="Submit" /&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p><em>The PHP code I am using to attempt to gather info from the database</em> (I have rewritten this a few times, this code also displays the "table.liam doesn't exist")</p> <pre><code> &lt;body&gt; &lt;?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 '&lt;br /&gt; Code: ' .$row['Code']; echo '&lt;br /&gt; Description: '.$row['Description']; echo '&lt;br /&gt; Category: '.$row['Category']; echo '&lt;br /&gt; Cut Size: '.$row['CutSize']; } mysql_close($con) ?&gt; &lt;/body&gt; </code></pre> <p>If anyone has any insight or can help me with this I would be very grateful! Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload