使用PHP下拉菜单列表

时间:2017-01-24 22:46:39

标签: php

我想为可用的库存数量创建一个下拉菜单列表。这是我到目前为止所做的代码,但它根本不起作用。出现此错误:

  

解析错误:语法错误,意外“篮子”(T_STRING),期待   ','或';'

    <?php

include("db.php");
//create a variable called $pagename which contains the actual name of the page
$pagename="Product Information";

//call in the style sheet called ystylesheet.css to format the page as defined in the style sheet
echo "<link rel=stylesheet type=text/css href=mystylesheet.css>";

//display window title
echo "<title>".$pagename."</title>";
//include head layout 
include ("headfile.html");

echo "<p></p>";
//display name of the page and some random text
echo "<h2>".$pagename."</h2>";


//retrieve the product id passed from the previous page using the $_GET superglobal variable
//store the value in a variable called $prodid
$prodid=$_GET['u_prodid'];
//echo "<p>Selected product Id: ".$prodid;

//query the product table to retrieve the record for which the value of the product id 
//matches the product id of the product that was selected by the user
$prodSQL="select prodId, prodName, prodPicName, 
prodDescrip , prodPrice, prodQuantity from product
where prodId=".$prodid;
//execute SQL query
$exeprodSQL=mysql_query($prodSQL) or die(mysql_error());
//create array of records & populate it with result of the execution of the SQL query

$thearrayprod=mysql_fetch_array($exeprodSQL);

//display product name in capital letters

echo "<p><left><b>".strtoupper($thearrayprod['prodName'])."</b></left>";
echo "<p><img src=images/".($thearrayprod['prodPicName']).">";
echo "<p><left>".($thearrayprod['prodDescrip'])."</left>";

echo "<br>";
echo "<br>";
echo "GBP<left> ".($thearrayprod['prodPrice'])."</left>";
echo "<br>";
echo "<br>";
echo "Number in stock:<left> ".($thearrayprod['prodQuantity'])."</left>";

//display form made of one text box and one button for user to enter quantity
//pass the product id to the next page basket.php as a hidden value
echo "<form action="basket.php" method=post>";
echo "<p><span style="text-align: center";>Enter required Quantity: ";
echo '<select name="options">';
for($i=1; $i<=4; $i++)
{
    echo "<option value=".$i.">".$i."</option>";
}
echo '</select>';

echo "<input type=hidden name=h_prodid value=".$prodid.">";
echo "<input type=submit value='Add to Basket'>";
echo "</span>";
echo "</form>";

//include head layout
include("footfile.html");
?> 

1 个答案:

答案 0 :(得分:0)

提交按钮必须位于<select>标记之外,而不是在循环创建选项中。

echo "<form action='basket.php' method='post'>";
echo "<p><span style='text-align: center';>Enter required Quantity: ";
echo '<select name="options">';
for($i=1; $i<=4; $i++)
{
    echo "<option value=".$i.">".$i."</option>";
}
echo '</select>';

echo "<input type='hidden' name='h_prodid' value='".$prodid."'>";
echo "<input type='submit' value='Add to Basket'>";
echo "</span>";
echo "</form>";

您还应该使用带有CSS的span而不是过时的<center>标记。你错过了<select name="options">字符串周围的引号。你应该在标签中加上属性值的引号。

相关问题