我一直试图制作一个带有下拉列表的表单,这些表单从不同的表中填充,然后将该数据上传到另一个表中。
我拼凑了以下代码但是在提交表单时,表格中的数据显示为“数组”而不是下拉列表中的选定项目,最后的“数量”提交正常。
<?php
include ('../connect.php');
if(isset($_POST['submit']))
{
$qty = $_POST['qty'];
$mob_name = $_POST['mob_name'];
$item_img = $_POST['item_img'];
$item_name = $_POST['item_name'];
//save the name of image in table
$query = mysql_query("INSERT INTO tbl_drop VALUES('','$mob_name','$item_img','$item_name','$qty')") or die(mysql_error());
}
$query_Recordset1 = "SELECT mob_name FROM tbl_img ORDER BY mob_name ASC";
$Recordset1 = mysql_query($query_Recordset1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$query_Recordset2 = "SELECT item_name FROM tbl_itm ORDER BY item_name ASC";
$Recordset2 = mysql_query($query_Recordset2) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
$query_Recordset3 = "SELECT item_img FROM tbl_itm ORDER BY item_name ASC";
$Recordset3 = mysql_query($query_Recordset3) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);
?>
<html>
<head>
<title></title>
</head>
<body>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="new_drop.php">
<label>Mob Name:
<select name="mob_name" id="mob_name">
<?php
do {
?>
<option value="<?php echo $row_Recordset1?>"><?php echo $row_Recordset1['mob_name']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</label>
<p>
<label>Item Name:
<select name="item_name" id="item_name">
<?php
do {
?>
<option value="<?php echo $row_Recordset2?>"><?php echo $row_Recordset2['item_name']?></option>
<?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
$rows = mysql_num_rows($Recordset2);
if($rows > 0) {
mysql_data_seek($Recordset2, 0);
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
}
?>
</select>
</label>
<p>
<label>Item Image:
<select name="item_img" id="item_img">
<?php
do {
?>
<option value="<?php echo $row_Recordset3?>"><?php echo $row_Recordset3['item_img']?></option>
<?php
} while ($row_Recordset3 = mysql_fetch_assoc($Recordset3));
$rows = mysql_num_rows($Recordset3);
if($rows > 0) {
mysql_data_seek($Recordset3, 0);
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
}
?>
</select>
</label>
<p>
<label>Quantity:
<input type='text' name='qty' />
</label>
<p>
<label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
</p>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
mysql_free_result($Recordset3);
?>
答案 0 :(得分:1)
您的代码中存在错误:
<option value="<?php echo $row_Recordset3?>"><?php echo $row_Recordset3['item_img']?></option>
应该是
<option value="<?php echo $row_Recordset3['item_img']?>"><?php echo $row_Recordset3['item_img']?></option>
$ row_Recordset3是一个包含值的数组。因此,如果您回显数组的值,它将显示为数组,并且选项块的值将成为数组。
因此您需要将选项值中的$row_Recordset3
更改为$row_Recordset3['item_img']
希望这会有所帮助:)