I can't figger out how to query my DB based on variable text entered in a text field and DB field names selected in a SELECT box in my form. I've posted the html and the PHP below and would be very grateful for some help.
PHP Below:
<?php
// DB connect info
$hostname = "127.0.0.1"; // Usually localhost.
$username = "client"; // If you have no username, leave this space empty.
$password = ""; // The same applies here.
$usertable = "partslist"; // This is the table you made.
$dbName = "Military_Catalog"; // This is the main database you connect to.
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
// QUERY
$query = mysql_query("SELECT * FROM $usertable WHERE $ddb LIKE '%$start%' LIMIT 0,30 ") or die (mysql_error());
while ($row = mysql_fetch_array($query))
{
$partnum=$row["0"];
$nsn=$row["1"];
$top_level_kit=$row["2"];
$description=$row["3"];
$engine_used_on=$row["4"];
echo"
<span style=\"font-family: Verdana, Geneva, Arial, helvetica, sans-serif; font-size: 11px; color: #444973; \">Part Number:</span> <span style=\" font: 9px verdana,arial; color:#717abf; font-weight: bold;\">$partnum</span><br />
<span style=\"font-family: Verdana, Geneva, Arial, helvetica, sans-serif; font-size: 11px; color: #444973; \">NSN:</span> <span style=\" font: 9px verdana,arial; color:#717abf; font-weight: bold;\">$nsn</span><br />
<span style=\"font-family: Verdana, Geneva, Arial, helvetica, sans-serif; font-size: 11px; color: #444973; \">Top Level Kit:</span> <span style=\" font: 9px verdana,arial; color:#717abf; font-weight: bold;\">$top_level_kit</span><br />
<span style=\"font-family: Verdana, Geneva, Arial, helvetica, sans-serif; font-size: 11px; color: #444973; \">Description:</span> <span style=\" font: 9px verdana,arial; color:#717abf; font-weight: bold;\">$description</span><br />
<span style=\"font-family: Verdana, Geneva, Arial, helvetica, sans-serif; font-size: 11px; color: #444973; \">Engine Used On:</span> <span style=\" font: 9px verdana,arial; color:#717abf; font-weight: bold;\">$engine_used_on</span> <br />
<hr noshade SIZE=1 color=#717abf>
";
};
// Error Results
if(mysql_num_rows($query)==0) {
echo"
<table height=100% width=100% valign=center>
<tr>
<td>
<center>
<span style=\"font-family: Verdana, Geneva, Arial, helvetica, sans-serif; font-size: 20px; color: #444973; font-weight: bold;\">
<a href=\"http://www.atec.com/db_any_query.php\">No results! Return to NSN Query</a>
</span>
</center>
</td>
</tr>
</table>
";
}
?>
HTML Below:
<html>
<head>
<title>ATEC Sample NSN Query Page</title>
</head>
<body>
<form name="search" method="post" action="search.php">
<input name="start" type="text" size="50" maxlength="50" size="11" tabindex=1 style="font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;" />
<?PHP
$connection = mysql_connect("127.0.0.1","client","");
$fields = mysql_list_fields("Military_Catalog", "partslist", $connection);
$columns = mysql_num_fields($fields);
echo "<select name=\"ddb\" size=\"1\" style=\"font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;\">";
//echo "<option>Select Search Item</option>";
//echo "<option>------------------</option>";
for ($i = 0; $i < $columns; $i++) {
echo "<option value=$i>";
echo mysql_field_name($fields, $i);
echo "</option>";
}
echo "</select>";
?>
<br />
<input type="submit" name="Submit" value="search" size="11" tabindex=5 style="font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;" />
<input type="reset" name="Reset" value="Reset" size="11" tabindex=6 style="font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;" />
</form>
</body>
</html>