Php下拉菜单

时间:2010-01-04 16:52:56

标签: php database

我使用以下代码将数据插入mysql数据库

<?php
$refselect  = $_POST['refselect'];
$refname    = $_POST['refname'];
$refemail   = $_POST['refemail'];
$refcnt     = $_POST['refcnt'];
$refdes     = $_POST['refdes'];
$referror   = $cberror = "<h1>Data not Added</h1><br/><br/><h3>Please Follow The Instructions</h3>";
$urefdb     = "INSERT INTO refdb(reftype,refname,refemail,refcnt,refdes) VALUES ('$refselect','$refname','$refemail','$refcnt','$refdes');"; 

include_once("db.php");

if ($refselect == "Select Type") die ("$referror");

if (empty ($refname)) die ("$referror");

if (mysql_query("$urefdb"))

{
echo "<h3>One Record Updated Successfully with the following Details </h3><br/>";
echo "Reference Type =$refselect <br/><br/>";
echo "Reference Name = $refname <br/><br/>";
echo "Reference E-Mail = $refemail <br/><br/>";
echo "Reference Description = $refdes <br/><br/>";

}
else
{
echo mysql_error();
}

?>

“refselect”数据来自页面的下拉菜单现在我想要,因为我通过这个表单添加数据另一个表单位于另一个页面pic“refname”来自数据库,因为我更新“refdb”下拉菜单相应地选择数据

现在该怎么办?

1 个答案:

答案 0 :(得分:2)

你必须使用MySQL选择填写另一页的下拉菜单,如:

$request = mysql_query("SELECT refselect FROM refdb");

然后遍历所有结果以填充组合框:

echo "<SELECT>";
while ($drow = mysql_fetch_assoc($request))
{
   echo "<OPTION>" . $drow['refselect'] . "</OPTION>";
}
echo "</SELECT>";

或类似的东西