<form method="POST" name="mailform" action="sendmail.php">
<fieldset>
<?php
require_once("mysql_connect.php");
$sql = mysql_query( " SELECT NAME FROM TABLE WHERE ID = ( SELECT ID FROM TABLE2 WHERE COLUMN = '$USERNAME') ORDER BY NAME");
echo "<select>";
while($row = mysql_fetch_array($sql)){
echo "<option value='".$row["NAME"]."'>".$row["NAME"]."</option>";
}mysql_free_result($sql);
echo "</select>";
?>
<input type="text" name = "name" placeholder = "name Required" ><br \><br \>
<input type="checkbox" name="instance[]" value="yes" checked="checked" \>instance1><br>
<input type="checkbox" name="instance[]" value="Yes" \>instance2<br><br \>
<input type="submit" name="email" value="Send Mail">
</fieldset> <br \>
</form> <br \><br \>
这是代码的一部分。我需要构建sendemail.php,它应该具有动态选择列表中的值以及复选框中的值。
最佳答案
<?php
require_once("mysql_connect.php");
$sql = mysql_query( " SELECT NAME FROM TABLE WHERE ID = ( SELECT ID FROM TABLE2 WHERE COLUMN = '$USERNAME') ORDER BY NAME");
echo "<select name='selection'>";
while($row = mysql_fetch_array($sql)){
echo "<option value='".$row["NAME"]."'>".$row["NAME"]."</option>";
}mysql_free_result($sql);
echo "</select>";
?>
更改上面的PHP代码..您将从动态选择列表中获取
$_POST['selection']
。编辑:
您将获得
$_POST['instance']
数组。<?php
$selected = $_POST['selection'];
$instances = array();
foreach ($_POST['instance'] as $instance)
{
$instances[] = $instance;
}
?>
现在,您将
$selected
作为动态选定值,并且$instances
具有一组已选中的复选框。