我正在创建一个由从数据库中提取的数据填充的表单。该信息是公司中用户的联系方式。例如手机号码。和电子邮件地址。我想做的事情是使用复选框选择要向哪些用户发送消息。该表单是在显示复选框、ID、姓氏、姓名、手机、电子邮件和部门的表中创建的。复选框值为= 对同一行信息的ID。如何在输入字段中显示值。这是我到目前为止的代码。
<form name="form1" id="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<?php
// setting variables
$db_host = "localhost";
$username = "userN";
$password = "PassW";
$db_name = "DB_name";
//Connect to db
$link = mysql_connect("$db_host","$username","$password");
// check connection
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// select table in db
$db = mysql_select_db("$db_name");
// check if db selected
if (!$db) {
die ('Can\'t use ' . $db_name . mysql_error());
}
// query data
$res = mysql_query('SELECT ID, Surname, Names, Mobile, EMail, Department FROM rars limit 0, 10');
// check if query is working
if (!$res) {
die('Invalid query: ' . mysql_error());
}
// setting table and heading
echo "<table height='50px' width='100%' border='1' align='center' cellpadding='0' cellspacing='4' bgcolor='#EEEEEE'>
<tr align='center'>
<td width='10'><font color='#222222' size='2'><strong></font></strong></td>
<td><font color='#222222' size='2'><strong>ID</font></strong></td>
<td><font color='#222222' size='2'><strong>Surname</font></strong></td>
<td><font color='#222222' size='2'><strong>Name</font></strong></td>
<td><font color='#222222' size='2'><strong>Mobile</font></strong></td>
<td><font color='#222222' size='2'><strong>EMail</font></strong></td>
<td><font color='#222222' size='2'><strong>Department</font></strong></td>
</tr>";
// populating array
while($row = mysql_fetch_array($res))
{
echo "<tr align='center'>";
//populating rest of columns
echo "<td><input type='checkbox' name='checkbox' value='$row[ID]'>" . "</td>";
echo "<td><font color='#111111' size='2'>" . $row['ID'] . "</font></strong></td>";
echo "<td><font color='#111111' size='2'>" . $row['Surname'] . "</font></strong> </td>";
echo "<td><font color='#111111' size='2'>" . $row['Names'] . "</font></strong></td>";
echo "<td><font color='#111111' size='2'>" . $row['Mobile'] . "</font></strong></td>";
echo "<td><font color='#111111' size='2'>" . $row['EMail'] . "</font></strong></td>";
echo "<td><font color='#111111' size='2'>" . $row['Department'] . "</font></strong></td>";
echo "</tr>";
}
echo "</table>";
// closing db
mysql_close($link);
?>
<br><br><input type="submit" name="submit" value="Submit" /> <br><br>
<?php
if($_POST['submit'])
{
if(isset($_POST['checkbox']))
{
$emails = $_POST['checkbox'];
echo "The following email addresses have been selected: <br />";
foreach($emails as $key => $value)
{
echo $value . "<br />";
}
}
else
{
echo "no email address selected";
}
}
?>
</form>
当您选择某些复选框并单击提交时,不会显示任何 ID。如果您能提供帮助,将不胜感激。谢谢丹尼