我试图确保数据库中的每一列都将从 HTML 中提取,但只有前两列会提取。最后三列不起作用。两个是文本值,最后一列是小数。有人可以告诉我我错过了什么吗?谢谢!
$colmName = $_POST["colName"];
$colmValue = $_POST["colValue"];
$count = 0;
if ($colmName = 'productID')
{
$theQuery = "SELECT * FROM products
WHERE productID = $colmValue";
$rSet = $db->query ($theQuery);
}
elseif ($colmName = 'categoryID')
{
$theQuery = "SELECT * FROM products
WHERE categoryID = $colmValue";
$rSet = $db->query($theQuery);
}
elseif ($colmName = 'productCode')
{
$theQuery = "SELECT * FROM products
WHERE (productCode = '$colmValue')";
$rSet= $db->query($theQuery);
}
elseif ($colName = 'productName')
{
$theQuery = "SELECT * FROM products
WHERE (productName = '$colmValue')";
$rSet = $db->query ($theQuery);
}
elseif ($colName = 'listPrice')
{
$theQuer = "SELECT * FROM products
WHERE listPrice = $colmValue";
$rSet = $db->query ($theQuery);
}
else
{
echo ('Enter a valid column name from the products table and an existing value. Either productID, categoryID, productCode, productName, or listPrice.');
include (index.html);
exit ();
}//end if
foreach($rSet AS $products)
{
$list .= $count.' '.$products['productID']
.' '.$products['categoryID']
.' '.$products['productCode']
.' '.$products['productName']
.' '.$products['listPrice']
.'<br>';
$count++;
}//foreach
echo ("<p>The data for $colmName with a value of $colmValue is listed below:<p>");
// echo ($list);//just to check if it works before putting it in a table
// echo ('<p>');//for spacing
?>
<DOCTYPE! html>
<html>
<head>
<title>Product Results</title>
</head>
<body>
<section>
<table border="1">
<tr><th>productID</th><th>categoryID</th><th>productCode</th><th>productName</th><th>listPrice</th></tr>
<tr><td><?php echo $products['productID'];?></td><td><?php echo $products['categoryID'];?></td><td><?php echo $products['productCode'];$
</table>
</section>
</body>
</html>