【发布时间】:2015-01-02 17:47:29
【问题描述】:
我有一个订单,产品在复选框中。所选项目应插入到数据库列中。我在编码方面还不是很好,所以如果你给我看一个例子会很棒。谢谢。
这是我的桌子:
<form name="form" method="POST">
<table width="623" height="283" border="0" align="center">
<tr>
<td width="146">Name:</td>
<td width="266"><label for="name"></label>
<input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td>Contact No:</td>
<td><label for="contactno"></label>
<input type="text" name="contactno" id="contactno" /></td>
</tr>
<tr>
<td>Address:</td>
<td><label for="address"></label>
<input type="text" name="address" id="address" /></td>
</tr>
<tr>
<td height="31">Select Items:</td>
<td>
<label>
<input type="checkbox" name="CheckboxGroup[]" value="sample one" id="CheckboxGroup_0" />
Checkbox</label>
<br />
<label>
<input type="checkbox" name="CheckboxGroup[]" value="sample two" id="CheckboxGroup_1" />
Sample</label>
<br />
<br />
</p></td>
</tr>
<tr>
<td>Payment Option:</td>
<td>
<label for="pay_option"></label>
<select name="pay_option" id="pay_option">
<option value="Counter">Counter</option>
<option value="BDO">BDO</option>
<option value="Smart Money">Smart Money</option>
</select>
</td>
</tr>
<tr>
<td>Claiming Option:</td>
<td>
<label for="claim_option"></label>
<select name="claim_option" id="claim_option">
<option value="Pick-up">Pick-up</option>
<option value="Shipping">Shipping</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</form>
基本上,无论用户选择什么,都应该在单击提交按钮时插入到 db 列中。我不知道它的 PHP 脚本。我使用 dreamweaver 和 mysql 工作台
PHP
你给我的代码在最底部。其余的都是在我插入记录 gui 时由 DW 生成的
<?php require_once('Connections/MCC.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
$insertSQL = sprintf("INSERT INTO order_form (name, address, contact_no, payment_option, claim_option, orders) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['contactno'], "text"),
GetSQLValueString($_POST['pay_option'], "text"),
GetSQLValueString($_POST['claim_option'], "text"),
GetSQLValueString(isset($_POST['CheckboxGroup[]']) ? "true" : "", "defined","'Y'","'N'"));
mysql_select_db($database_MCC, $MCC);
$Result1 = mysql_query($insertSQL, $MCC) or die(mysql_error());
}
//-------added this---------
if (isset($_POST['submit']))
{
$implode=implode(",",$_POST['CheckboxGroup']);
mysql_query("INSERT INTO order_form (orders) VALUES ('".$implode."')") ;
}
?>
【问题讨论】:
-
请拨打tour 并阅读How to Ask,了解我们对问题的期望。以目前的形式,您的问题无法回答,因为它太宽泛了。请收集更多信息,然后edit您的帖子。
标签: mysql database checkbox insert dreamweaver