当前位置: 代码迷 >> PHP >> radio的值如何写入数据库
  详细解决方案

radio的值如何写入数据库

热度:327   发布时间:2016-04-28 18:56:53.0
radio的值怎么写入数据库
本帖最后由 lihui4512z 于 2014-07-03 17:21:43 编辑


其他几列都是动态获取的,都能够成功写入数据库。

现在问题就在这一句

<td style="text-align:center;font-size:14px;"><input type="radio" name="<?php echo $_values;?>" value="正常" style="zoom:150%;" />正常
<input type="radio" name="<?php echo $_values;?>" value="不正常" style="zoom:150%;" />不正常</td>


感觉name这样定义好像不对,但又不知道怎么弄了。请问怎样可以将radio选中的值写入数据库?name不好用常量。


附整个表单代码:

<form name="ksdj" method="post" action="cldj.php">
<table>
<tr><th colspan=7>开始点检</th></tr>

<tr><td colspan=3 style="font-weight:bold;text-align:center;">车辆选择:<select name="hao1"> <?php 

while (!!$_rows = _fetch_array_list($_result)){ ?>
<option value="<?php echo $_rows['hao'];?>"> <?php echo $_rows['hao'];?></option> <?}?></select>
</td>
<td colspan=1 style="font-size:16px;font-weight:bold;text-align:center;">工号:<?php echo $_COOKIE["name"]; ?></td>
<td colspan=1 style="font-size:16px;font-weight:bold;text-align:center;">日期:<?php echo date('Y-m-d',time()); ?>
<input name="time" type="hidden" value="<?php echo date('Ymd',time());?>"/>
</td></tr>
<tr><td style="font-weight:bold;text-align:center;">编号</td>
<td style="font-weight:bold;text-align:center;">点检项目</td>
<td style="font-weight:bold;text-align:center;">点检方法</td>
<td style="font-weight:bold;text-align:center;">点检标准</td>
<td style="font-weight:bold;text-align:center;">状 态</td>
</tr>
<?php 
while (!!$_rows = _fetch_array_list($_result2)){
?>
<tr><td style="width:6%;text-align:center;font-size:14px;"><?php echo $_rows['bh'];?>
<input name="bh[]" type="hidden" value="<?php echo $_rows['bh'];?>"/>
</td><?php $_values=$_rows['bh'];?>
<td style="width:20%;text-align:center;font-size:14px;"><?php echo $_rows['xm']?>
<input name="xm[]" type="hidden" value="<?php echo $_rows['xm'];?>"/>
</td>
<td style="width:12%;text-align:center;font-size:14px;"><?php echo $_rows['fangfa']?>
<input name="fangfa[]" type="hidden" value="<?php echo $_rows['fangfa'];?>"/>
</td>
<td style="width:44%;text-indent:10px;font-size:14px;"><?php echo $_rows['biaozhun']?>
<input name="biaozhun[]" type="hidden" value="<?php echo $_rows['biaozhun'];?>"/>
</td>
<td style="text-align:center;font-size:14px;"><input type="radio" name="<?php echo $_values;?>" value="正常" style="zoom:150%;" />正常
<input type="radio" name="<?php echo $_values;?>" value="不正常" style="zoom:150%;" />不正常</td>
</tr>

<?php
}?>
<tr><td colspan=6 style="text-align:center;">
<input type="submit" name="send" class="ksdj" value="提交" style=font-size:18px;/>
<input type="reset" class="reset" value="重置" /></td></tr>
</table>
</form>



【cldj.php】

<?php 
header("Content-type: text/html; charset=utf-8");
require ('common.php');

$hh=$_POST['hao1'];
$aa=$_POST['bh'];
$bb=$_POST['xm'];
$cc=$_POST['fangfa'];
$dd=$_POST['biaozhun'];
$_gh=$_COOKIE["name"]; 
$_time=$_POST['time'];

$name=implode(_fetch_array_list(mysql_query("SELECT name FROM jsy WHERE gonghao = $_gh")));

if (is_array($aa)){
foreach ($aa as $i=>$v){
 mysql_query("INSERT INTO djjl (hao,bh,xm,fangfa,biaozhun,gonghao,name,time,zt) VALUES (
'$hh',
                                                                '$v',
'{$bb[$i]}',
'{$cc[$i]}',
'{$dd[$i]}',
'$_gh',
'$name',
'$_time'

)" )or die('SQL执行失败!'.mysql_error());}}
mysql_close();
_alert_location('添加成功!','ksdj.php');
?>

------解决方案--------------------
你那样定义name,后台还有重组数组格式。建议你这样定义name值:
name="post[$_rows['bh']]['bh']"
name="post[$_rows['bh']]['xm']"
这样每一行就是一个数组。
后面的radio也是一样, name="post[$_rows['bh']]['status']"
------解决方案--------------------
引用:
你那样定义name,后台还有重组数组格式。建议你这样定义name值:
  相关解决方案