我在让我的 php 表单正常运行时遇到了一些困难。我正在尝试使用多个下拉框,它们都引用数据库并从各自的值中填充自己。
正如您在下面的代码中看到的那样,我正在尝试使用“电子邮件”和“类型”框中的结果创建查询。任何人都可以帮忙吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?php
$host = "****";
$dbname = "****";
$username = "****";
$password = "****";
@ $connection = mysql_connect($host, $username, $password);
@ mysql_select_db($dbname,$connection);
if (!$connection) {
die('=( Could not connect: ' . mysql_error());
}
echo '<b>Connected successfully to $dbname</b>';
mysql_close($connection);
/*
Check to see if connection was successful
*/
?>
<form name="survey" method="post" action="scripts/report_script.php" onSubmit="">
Email:
<select name="email">
<!-- Begin email selection -->
<?php
mysql_connect($host, $username, $password);
mysql_select_db($dbname);
$email_query = "SELECT sgl_userID,sgl_user_email FROM tbl_sgl_user";
$email_result = mysql_query($email_query);
while ($row = mysql_fetch_array($email_result)){
echo '<option value="'.$row['sgl_userID'].'">'.$row['sgl_user_email'].'</option>';
}
?>
</select>
<!-- End email selection -->
<!--Start Survey Type selection-->
<select name="type">
<option value="government">Government</option>
<option value="sport">Sport</option>
<option value="school">School</option>
</select>
<!--End Survey Type selection-->
<!--Start Date selection-->
<select name="date">
<?php
mysql_connect($host, $username, $password);
mysql_select_db($dbname);
$date_query = "SELECT survey_date FROM tbl_survey WHERE survey_name='$type' AND sgl_userID='$email'";
$date_result = mysql_query($date_query);
while ($row = mysql_fetch_array($date_result)){
echo '<option value="'.$row['survey_date'].'">'.$row['survey_date'].'</option>';
}
?>
</select>
<!--End Date selection-->
<input type="Submit" name="Submit" value="Submit" />
</form>
</body>
</html>