Forum Moderators: coopster
So when a client came to me and asked if I could create a website that would allow users to search the traceability details of his products, I rose to the challenge and said yes.
Let me exlpain further: The client produces a fish product, and has a simple (one table) database, with about 5 or 6 fields, that give details about the harvesting dates, the geographic origin, the batch number, etc. for each batch of fish.
I managed to create the table in a mySql database using phpMyAdmin. I also managed to create a set of "out-of-the-box" user admin tools for the client, by installing a free script (phpMyEdit I think).
However, my remaining problem is: what is the pHp code I need to allow users, on the website to enter a batch number, so that a page containing the corresponding record will be returned?
I have looked at various tutorials but can't seem to find where I'm looking for -- and don't really know where to start. Can anyone help?
(Just to be clear: I want to create a page that says "Enter batch number", and has a box where they can enter the number that they find on the tag of the product. There is no ambiguity about the batch number -- the user will either know it exactly or they won't.)
<?php
if(isset($_POST["batch"]))
{
$batch = $_POST["batch"];
$query = "SELECT batch, fish, geography FROM table WHERE batch = $batch";
$conn = mysql_connect("host", "user", "passwd") or die(mysql_error());
mysql_select_db("dbname", $conn) or die(mysql_error());
$result = mysql_query($query, $conn) or die(mysql_error());
?>
<table><tr><th>All the headers</th><th></th></tr>
<?php
while($answer = mysql_fetch_array($result))
{
echo "<tr><td>".$answer["fish"]."</td><td>".$answer["geography"]."</td></tr>";
}
echo "</table>";
}
else
{
?>
<form action="index.php" method="POST">
Enter the batch number: <input type="text" name="batch">
</form>
<?php
}
?>
However, when I go into the page and enter "SS81" (a sample batch number) into the input box, I get this error returned:
Unknown column 'SS81' in 'where clause'
Any ideas?
[edited by: michael_heraghty at 5:10 pm (utc) on April 15, 2005]