我创建了一个html页面。这是以下代码:
<title>Post AD</title>
</head>
<body>
<form method="POST" action="postad.php">
<table>
<tr>
<td>AdName:</td>
<td><input type="text" name="adname"></td>
</tr>
<tr>
<td>AdCategory</td>
<td>
<select name="categories">
<?php include 'getcategories.php';
echo '<option value="'.$categoryname.'">'.$categoryname.'</option>';
?>
</select>";
</td>
</tr>
<tr>
<td>Contact Number</td>
<td><input type="text" name="contactnumber"></td>
</tr>
<tr>
<td>Image</td>
<td><input type="text" name="image"></td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" name="description"></td>
</tr>
<tr>
<td>Expiration Date</td>
<td><input type="text" name="expirationdate"></td>
</tr>
<tr>
<td id="btn"><input type="submit" value='submit' name="submit"></td>
</tr>
</table>
</form>
</body>
</html>
我还有另一个php页面getcategories.php
<?php include 'connect.php';
$sql = "SELECT CatName FROM categories order by CatName";
$result = $db->query($sql);
// $options="";
//echo "<select value='categories'>";
while($row = $result->fetch_array()) {
$categoryname=$row['CatName'];
//echo "$categoryname\n";
//$options= '<option value="'.$categoryname.'">'.$categoryname.'</option>';
// echo "$options\n";
// echo '<option value="'.$categoryname.'">'.$categoryname.'</option>';
}
// echo "</select>";
?>
getcategories.php页面的主要目标是从数据库中提取数据,页面postad.html页面是将getctegories.php的数据显示在postad.html的下拉列表中。有没有办法不使用java脚本只用php和mysql来做这个吗?请帮助。谢谢。