【发布时间】:2013-03-06 13:20:25
【问题描述】:
刚刚从事一个小型大学项目以开发电子商务网站。我已经获得了一些代码,我正在根据自己的需要进行更改。
我目前在让一些数组在选项和选择标记中工作时遇到问题。不同之处在于这些数组中的每一个都有一个与之相关的动作,例如,移动到另一个页面。
问题似乎是选项标签中没有使用此操作。如此处所示http://mkiddr.com/phptests/shopping/
这是我编辑前的原始代码:
<body>
<div id="wrapper">
<div id="header">
<p><a href="index.php">Home</a> | Browse:
<?php
$q="SELECT c_id, c_name FROM sc_cat";
$result = mysqli_query($_SESSION['conn'],$q);
while ($row = mysqli_fetch_row($result)){
echo "<a href='category.php?id=$row[0]'>$row[1]</a> ";
}
unset($q); //unset query variable
mysqli_free_result($result); //free result
?>
</div>
<div id="content"><!-- note this is an opening tag -->
这是我编辑的代码(不起作用)
<body>
<div id="wrapper">
<div id="header">
<p><a href="index.php">Home</a> | Browse:
<select>
<?php
$q="SELECT CategoryID, CategoryName FROM ProductCategories";
$result = mysqli_query($_SESSION['conn'],$q);
while ($row = mysqli_fetch_row($result)){
echo "<option value='category.php?id=".$row[0]."'>".$row[1]."</a></option>";
//display categories
}
unset($q); //unset query variable
mysqli_free_result($result); //free result
?>
</select>
</div>
<div id="content"><!-- note this is an opening tag -->
如果有人能帮我们解决这个问题,我们将不胜感激!
【问题讨论】:
-
你在
</option>之前有一个无关的</a>。 -
即使这只是一个大学项目,也要警惕 sql 注入。使用参数化程序。我刚刚运行了这个并得到了你所有产品的列表
http://mkiddr.com/phptests/shopping/category.php?id=1 or 1=1。我本可以轻松地运行类似http://mkiddr.com/phptests/shopping/category.php?id=1;DROP TABLE ProductCategories;--的东西并毁掉你所有的辛勤工作。见bobby-tables.com -
@Matt Kidd Uhm,为什么选择 Simon 的答案是正确的 - 据我所知,您正在使用我的解决方案
-
非常感谢凯文。这实际上是我的标准的一部分,我只是专注于把所有东西放在一起。但是,您确实节省了我寻找弱点的时间!
标签: php html arrays select option