正在開發一個小型大學項目來開發電子商務網站。我已經提供了一些代碼,並且正在根據我的需要改變它。PHP選項標籤和數組
我目前有一個問題,讓一些數組在選項和選擇標記中工作。不同之處在於這些數組中的每一個都有與之相關的動作,例如移動到另一個頁面上。
問題似乎是這個動作沒有在選項標籤中使用。由於這裏看到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 -->
真的很感激,如果有人能夠給我們一個用這個手!
您在''之前有一個無關的''。 – Barmar 2013-03-06 13:29:12
即使這只是一個大學項目要小心SQL注入。使用參數化程序。我只是跑了這個,並得到了所有產品的列表http://mkiddr.com/phptests/shopping/category.php?id=1或1 = 1'。我可以很容易地運行這樣的'http://mkiddr.com/phptests/shopping/category.php?id=1;DROP TABLE ProductCategories; - '並且毀了你所有的努力工作。見http://bobby-tables.com/ – 2013-03-06 13:34:14
@Matt Kidd嚴姆,爲什麼西蒙的回答被證明是正確的 - 你正在使用我的解決方案,據我所知 – Stormherz 2013-03-06 13:50:12