您好,请教一个问题,请问在php接收表单数据页面内怎么利用js获得复选框的value值插入到数据库内?
QQ:1274731799
补充:表单内有多个问题,每个问题下都有许多复选框选项
QQ:1274731799
补充:表单内有多个问题,每个问题下都有许多复选框选项
答案:<?php
/*
* Created on 2011-6-21
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
include ("admin_head.php");
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$url = $_SERVER["REQUEST_URI"];
$url = parse_url($url);
$url = $url[path];
$User_ID = $_GET[User_ID];
$User_Authr = $_GET[User_Authr];
include_once ("conn.php");
$db->getinfo("map_info_tb");
$num_all = $db->num_rows();
while ($row = $db->showinfo()) {
$Map_ID[] = $row[0];
$Map_Name[] = $row[1];
}
$db->getinfo1("user_map_list", "User_ID", "'$User_ID'");
$num_old = $db->num_rows();
while ($row = $db->showinfo()) {
$selected[] = $row[1];
}
?>
<form id="form1" name="form1" method="post" action="user_info_edit.php?User_ID=<?=$User_ID?> & User_Authr=<?=$User_Authr?>">
<p>
<?
for ($i = 0; $i < $num_all; $i++) {
?>
<label>
<input type="checkbox" name="checkbox<?=$i?>" value="<?=$Map_ID[$i]?>" <?for($j=0;$j<$num_old;$j++){if($selected[$j]==$Map_ID[$i])echo "checked=\"checked\"";}?>/>
<?=$Map_Name[$i]?></label>
<br />
<?
}
?>
</p>
<input type="submit" name="submit" value="提交"><input type="reset" name="reset" value="重置">
</form>
<?
if (isset ($_POST['submit']) && $_POST['submit']) {
for ($i = 0; $i < $num_all; $i++) {
if (isset ($_POST["checkbox$i"])) {
$new_selected[] = $_POST["checkbox$i"];
}
}
include_once("conn.php");
$db->delete("user_map_list","User_ID","'$User_ID'");
$num_new = count($new_selected);
for ($i = 0; $i < $num_new; $i++) {
include_once ("conn.php");
$db->insert("user_map_list", "User_ID,Map_ID", "'$User_ID','$new_selected[$i]'");
}
$url="user_info.php?User_ID=$User_ID & User_Authr=$User_Authr";
echo "<script language=\"javascript\">location.href='$url';</script>";
}
?>
希望对你有帮助!
其他:一定要用JS吗……php本身不是也能传值到数据库里面吗??
上一个:PHP 比较好用的框架有那些,突出的特点是什么,最好有框架源码及框架手册
下一个:为什么php获取不到首字母X 如下:只能得到R