请问各位:
在同一个页面上面有两组复选框(两组复选框的值是动态从数据库里提取的),现在要把两组复选框选中的值保存到数据库里面去并且每一组复选框选中的值保存到不同的字段里面(比如第一组复选框的值保存到aa表的name1字段,第二组复选框的值保存到aa表的name2字段)最好在我代码上改!<?
$j=1;
//$k=1;
$connect=mysql_connect('localhost','root','123');
$select=mysql_select_db('DDS',$connect);
$query="select * from exes";
$result=mysql_query($query);
$result_1=mysql_query($query);
mysql_query('set names utf8');
echo "<meta http-equiv='Content-Type' content='text/html; charset = utf-8'/>";
echo "<html>";
echo "<title>........</title>";
echo "</head>";
echo "<head>";
echo "<body>";
echo"<form id='form1' name='form1' method='post' action='b.php'>";
echo "<center>";
echo "<table border='1'>";
echo "<tr>";
while ($row_1=mysql_fetch_array($result)) {
echo "<td>";
echo "<input name='chk[]' type='checkbox' value=".$j."/>";
print_r($row_1[1]);
$j++;
echo "</td>";
}
echo "</tr>";
echo "<input type='hidden' name='countchk' value=".$j.">";
echo "</table>";
echo "<br>";
echo "<br>";
echo "<br>";
//涉密后缀//echo "<center>";
echo "<table border='1'>";
echo "<tr>";
while ($row_2=mysql_fetch_array($result_1)) {
echo "<td>";
echo "<input name='chk[]' type='checkbox' value=".$j."/>";
print_r($row_2[2]);
$j++;
echo "</td>";
}
echo "</tr>";
echo "<input type='hidden' name='countchk' value=".$j.">";
echo "</table>";
echo "<input type='submit' name='check' value='提交' />";if($check)
{
for($i=0;$i<=$countchk;$i++)
{
echo $chk[$i]."<br>"; if ($chk[$i]!=""){
//$lm=$lm.$chk[$i]."|";
//$query_1="insert into customer(name2) values('','AutoCAD',".$row_1[$chk[$i]].")";
}
}
}
//echo $lm;echo "</center>";
echo "</form>";
echo "</body>";
echo "</html>";?>
<?php
extract($_GET);
extract($_POST);
//echo $chk[0];
?>
这是我用来实验的代码
在同一个页面上面有两组复选框(两组复选框的值是动态从数据库里提取的),现在要把两组复选框选中的值保存到数据库里面去并且每一组复选框选中的值保存到不同的字段里面(比如第一组复选框的值保存到aa表的name1字段,第二组复选框的值保存到aa表的name2字段)最好在我代码上改!<?
$j=1;
//$k=1;
$connect=mysql_connect('localhost','root','123');
$select=mysql_select_db('DDS',$connect);
$query="select * from exes";
$result=mysql_query($query);
$result_1=mysql_query($query);
mysql_query('set names utf8');
echo "<meta http-equiv='Content-Type' content='text/html; charset = utf-8'/>";
echo "<html>";
echo "<title>........</title>";
echo "</head>";
echo "<head>";
echo "<body>";
echo"<form id='form1' name='form1' method='post' action='b.php'>";
echo "<center>";
echo "<table border='1'>";
echo "<tr>";
while ($row_1=mysql_fetch_array($result)) {
echo "<td>";
echo "<input name='chk[]' type='checkbox' value=".$j."/>";
print_r($row_1[1]);
$j++;
echo "</td>";
}
echo "</tr>";
echo "<input type='hidden' name='countchk' value=".$j.">";
echo "</table>";
echo "<br>";
echo "<br>";
echo "<br>";
//涉密后缀//echo "<center>";
echo "<table border='1'>";
echo "<tr>";
while ($row_2=mysql_fetch_array($result_1)) {
echo "<td>";
echo "<input name='chk[]' type='checkbox' value=".$j."/>";
print_r($row_2[2]);
$j++;
echo "</td>";
}
echo "</tr>";
echo "<input type='hidden' name='countchk' value=".$j.">";
echo "</table>";
echo "<input type='submit' name='check' value='提交' />";if($check)
{
for($i=0;$i<=$countchk;$i++)
{
echo $chk[$i]."<br>"; if ($chk[$i]!=""){
//$lm=$lm.$chk[$i]."|";
//$query_1="insert into customer(name2) values('','AutoCAD',".$row_1[$chk[$i]].")";
}
}
}
//echo $lm;echo "</center>";
echo "</form>";
echo "</body>";
echo "</html>";?>
<?php
extract($_GET);
extract($_POST);
//echo $chk[0];
?>
这是我用来实验的代码
<input type="checkbox" name="a1[]">
<input type="checkbox" name="a1[]">
<input type="checkbox" name="a2[]">
<input type="checkbox" name="a2[]">
</form><?php
foreach($_POST as $k=>$v)
{
$query[] = "$k = '".implode(",",$v)."'";
}
mysql_query("INSERT INTO table SET ".implode(",",$query));
?>