我有一个非常简单的表单,其中包含一些文本字段和 2 个复选框。该表单有效,除非选中两个复选框,只有第一个复选框会添加到数据库中。
到目前为止我有这个:
<?php require_once('connectionsettings.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
. . .
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
# ------------ edit begins here ------------ #
if(count($articletags) > 0)
{
$articletags_string = implode(",", $articletags);
}
# ------------ edit ends here ------------ #
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO articles (articletitle, articledescription, articletags) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['articletitle'], "text"),
GetSQLValueString($_POST['articledescription'], "text"),
GetSQLValueString($_POST['articletags[]'], "text")); # --Edited here also
mysql_select_db($database_MySQL_CSFTDB, $MySQL_CSFTDB);
$Result1 = mysql_query($insertSQL, $MySQL_CSFTDB) or die(mysql_error());
}
?>
<!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">
. . .
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
. . .
<tr>
<td align="right"> </td>
<td align="left"><p>
<label> # -- added []s to article name --
<input type="checkbox" name="articletags[]" value="checkbox" id="articletags_0" />
Checkbox</label>
<br />
<label>
<input type="checkbox" name="articletags[]" value="checkbox 2" id="articletags_1" />
Checkbox</label>
<br />
<br />
</p></td>
</tr>
. . .
</body>
</html>