Okay, for starters, I have a Table in MySQL with the columns "barcode","description", and "quantity". I have two pages, 1 HTML and 1 PHP. The HTML has a form in it to accept a barcode scan, or manual text entry. Based on that entry, I want it to return a row, starting with the barcode that was entered in on the HTML form. So far, I can enter anything and it will return the whole table.
The HTML looks like this:
<head>
<font color="00CC00">
<title>Search</title>
</head>
<body bgcolor="000000">
<h2>Find Product</h2>
<form name="search" method="post" action="Barcode Search.php">
<input type="text" name="find" placeholder="Click to Scan" />
<input type="submit" name="search" value="Submit" />
</form>
</body>
</html>
Short, sweet and to the point! The .PHP look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Inventory List</title>
<body bgcolor="000000">
<font color="00cc00">
<?php
//Table
echo "<table style='border: solid 1px green;'>";
echo "<tr><th>Barcode</th><th>Description</th><th>Quantity</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width:150px;border:1px solid green;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "
";
}
}
//Connection Info
$servername = "127.0.0.1";
$username = "XXXX";
$password = "XXXXX";
$dbname = "test";
//Connection Started, Data pulled
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM inventory ");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
//Error Check
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
// Take Text entry and fetch the SQL Row
//Kill Connection
$conn = null;
echo "</table>";
?>
</center>
</body>
</html>
I'd very much appreciate a point in the right direction! Thanks in advance!