<?php
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("tnews2") or die(mysql_error());
$query = "SELECT name,id FROM categories ORDER BY ID DESC LIMIT 0,6";
$result = mysql_query($query) or die(mysql_error()."[".$query."]");?>
<select name="categories">
<?php while ($row = mysql_fetch_array($result)){
?>
<option value=" <?php $row['path']; ?> ">
<?php echo $row['name']; ?>
</option>
<?php
}
?>
</select>?>
所以这是选择选项菜单,它是我从数据库中读取的值,但是当我尝试获取所选值时,我只会得到第一个。
<?php
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("tnews2") or die(mysql_error());
if(!empty($_POST['title']) && !empty($_POST['date']) && !empty($_POST['txt']) && !empty($_POST['image'])){
$TITLE=$_POST['title'];
$DATE=$_POST['date'];
$TXT=$_POST['txt'];
$IMAGE=$_POST['image'];
$CATEGORIES=$_POST['categories'];
echo $CATEGORIES;
$ANSWER=$_POST['main'];
$MAINPAGE=0;
您能帮我个忙吗?
最佳答案
编辑:(减少您的代码)
<?php
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("tnews2") or die(mysql_error());
$query = "SELECT name,id,path FROM categories ORDER BY ID DESC LIMIT 0,6";
$result = mysql_query($query) or die(mysql_error()."[".$query."]");
?>
<select name="categories">
<?php
while ($row = mysql_fetch_array($result))
{
echo "<option value='".$row['path']."'>'".$row['name']."'</option>";
}
?>
</select>