I have created a dynamic drop down list, now I want to add the value from drop down list into my database. I am displaying 'Category_Name' to the user, and want to store 'Category_ID' in the database. I have written the following code. Kindly check it.
我已经创建了一个动态下拉列表,现在我想将下拉列表中的值添加到我的数据库中。我向用户显示“Category_Name”,并希望在数据库中存储“Category_ID”。我已经写了下面的代码。请检查它。
$select_query= "Select * from category";
$select_query_run = mysql_query($select_query);
echo "<select name='category'>";
while ($select_query_array= mysql_fetch_array($select_query_run) )
{
echo "<option value= '$select_query_array['category_id']' >".htmlspecialchars($select_query_array["name"])."</option>";
}
$selectTag= "</select>";
echo $selectTag;
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in F:\xampp\htdocs\CMS\insert_product.php on line 50
解析错误:语法错误,意外“(T_ENCAPSED_AND_WHITESPACE),期望标识符(T_STRING)或变量(T_VARIABLE)或数字(T_NUM_STRING)在F:\xampp\htdocs\CMS\insert_product中。php在50行
2 个解决方案
#1
1
Change -
的变化,
echo "<option value= '$select_query_array['category_id']' >".htmlspecialchars($select_query_array["name"])."</option>";
TO
来
echo "<option value='".$select_query_array['category_id']."'>".htmlspecialchars($select_query_array["name"])."</option>";
and add last brace as suggested by @bansi if it is not.
如果不是的话,添加@bansi建议的最后一个括号。
Let me know if it fix or not.
如果修好了就告诉我。
#2
1
while ($select_query_array= mysql_fetch_array($select_query_run) )
{
echo "<option value= '$select_query_array['category_id']' >".htmlspecialchars($select_query_array["name"])."</option>";
$selectTag= "</select>";
echo $selectTag;
should be
应该是
while ($select_query_array= mysql_fetch_array($select_query_run) )
{
echo "<option value= '{$select_query_array['category_id']}' >".htmlspecialchars($select_query_array["name"])."</option>";
}
$selectTag= "</select>";
echo $selectTag;
You are missing closing brace for the while loop. You are also missing braces around the variable to replace.
在while循环中,您将丢失关闭括号。您还缺少要替换的变量周围的大括号。
#1
1
Change -
的变化,
echo "<option value= '$select_query_array['category_id']' >".htmlspecialchars($select_query_array["name"])."</option>";
TO
来
echo "<option value='".$select_query_array['category_id']."'>".htmlspecialchars($select_query_array["name"])."</option>";
and add last brace as suggested by @bansi if it is not.
如果不是的话,添加@bansi建议的最后一个括号。
Let me know if it fix or not.
如果修好了就告诉我。
#2
1
while ($select_query_array= mysql_fetch_array($select_query_run) )
{
echo "<option value= '$select_query_array['category_id']' >".htmlspecialchars($select_query_array["name"])."</option>";
$selectTag= "</select>";
echo $selectTag;
should be
应该是
while ($select_query_array= mysql_fetch_array($select_query_run) )
{
echo "<option value= '{$select_query_array['category_id']}' >".htmlspecialchars($select_query_array["name"])."</option>";
}
$selectTag= "</select>";
echo $selectTag;
You are missing closing brace for the while loop. You are also missing braces around the variable to replace.
在while循环中,您将丢失关闭括号。您还缺少要替换的变量周围的大括号。