Php 来自POST的codeigniter中的空值
更新:Php 来自POST的codeigniter中的空值,php,arrays,codeigniter,post,null,Php,Arrays,Codeigniter,Post,Null,更新: Error Number: 42S22/1054 Unknown column 'Array' in 'field list' INSERT INTO `attendance` (`event_date`, `event_time`, `event_info`, `player_id`, `is_present`, `notes`) VALUES ('2017-03-08', '11:00:00 AM', 'other', NULL, Array, 'notes') “NU
Error Number: 42S22/1054
Unknown column 'Array' in 'field list'
INSERT INTO `attendance` (`event_date`, `event_time`, `event_info`, `player_id`, `is_present`, `notes`) VALUES ('2017-03-08', '11:00:00 AM', 'other', NULL, Array, 'notes')
“NULL”应为“player_id”,“Array”应存在或不存在。非常坚持这一点,所以感谢你迄今为止的所有帮助,我真的很感激
我正在尝试创建一个考勤表,它将保存一个人的id,然后有两列-一列用于表示出席,另一列用于标记缺席。因此,我将一次性向数据库添加多行
我刚刚从视图中添加了代码,因为我知道我的控制器和模型很好,因为其他输入字段工作正常
对于每一行,我希望它输入玩家id以及他们是否在场。在我的数据库中,它是一个枚举“是”或“否”。我知道这可能是不正确的,所以谢谢你的建议
<div class="container-fluid">
<div class="form-group">
<div class=".col-xs-12 .col-md-6">
<h2 class="brand-before text-center"></h2>
<table class="table table-sm table-bordered tabular_datable-condensed table-hover" id="playertable" name="player_id">
<tr>
<th>Player ID</th>
<th>Player first name</th>
<th>Player surname</th>
<th>Add</th>
</tr>
<tr class="clickable-row">
<?php foreach ($query->result_array() as $row): {?>
<tr>
<td><?php echo $row['player_id'];?></td>
<td><?php echo $row['player_first_name'];?></td>
<td><?php echo $row['player_last_name'];?></td>
<td align="left">
<label>
<input type="radio" name="attendance[<?php echo $row['player_id']; ?>]" value="Yes" <?php echo set_radio('attendance', 'Yes', TRUE); ?> >Present
</label>
 
<label>
<input type="radio" name="attendance[<?php echo $row['player_id']; ?>]" value="No" <?php echo set_radio('attendance', 'No', TRUE); ?> >Absent
</label></td>
<?php } ?>
<?php endforeach; ?>
</tr>
</table>
修正输入
<label>
<input type="radio" name="attendance<?php echo $row['player_id']; ?>"
value="yes"<?php if (isset($attendance) && $attendance=="yes")
echo "checked";?> > Present
</label>
使用echo检查发送到控制器的输入;打印本->输入->发布;出口然后找出输入的问题所在。同时从单选按钮中删除阵列
<table>
<thead>
<tr>
<th>Player ID</th>
<th>Player name</th>
<th>Attending</th>
</tr>
</thead>
<tbody>
<?php foreach($query->result_array() as $row) : ?>
<tr>
<!-- hidden input for player_id -->
<?php echo form_hidden('player_id[' .$row["player_id"]. ']', $row['player_id']); ?>
<!-- /hidden input for player_id -->
<td><?php echo $row['player_id']; ?></td>
<td><?php echo $row['player_name']; ?></td>
<td>
<label>
<input type="radio" name="attendance[<?php echo $row['player_id']; ?>]" value="Yes" <?php echo set_radio('attendance', 'Yes', TRUE); ?> >Present
</label>
<label>
<input type="radio" name="attendance[<?php echo $row['player_id']; ?>]" value="No" <?php echo set_radio('attendance', 'No'); ?> >Absent
</label>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
一旦提交,就会发布多个数组
控制器
以下是输出员额:
下一步,你的模型调用$this->db->insert_batch for你想对性别做什么?@KristjanKica抱歉,这只是一个输入错误-它是代码中的考勤也许你想在关闭输入标记之前使用这段代码?不是在你关闭标签@KristjanKica谢谢,我更改了代码-这就是你的意思吗?或者两个标签都会在第二个收音机盒之后关闭。这两种方式似乎都不起作用。请出示您的表格提交?为什么name=attention[]作为数组?是批量输入吗?使用set_收音机“出席”、“是”;显示已检查。谢谢,我更改了这个。我还添加了我的模型代码,以防这里也有问题,因为它仍然显示为空值,试图插入到我的错误日志中。很高兴它能够提供帮助
<table class="table table-sm table-bordered tabular_datable-condensed table-hover" id="playertable" name="player_id">
<table>
<thead>
<tr>
<th>Player ID</th>
<th>Player name</th>
<th>Attending</th>
</tr>
</thead>
<tbody>
<?php foreach($query->result_array() as $row) : ?>
<tr>
<!-- hidden input for player_id -->
<?php echo form_hidden('player_id[' .$row["player_id"]. ']', $row['player_id']); ?>
<!-- /hidden input for player_id -->
<td><?php echo $row['player_id']; ?></td>
<td><?php echo $row['player_name']; ?></td>
<td>
<label>
<input type="radio" name="attendance[<?php echo $row['player_id']; ?>]" value="Yes" <?php echo set_radio('attendance', 'Yes', TRUE); ?> >Present
</label>
<label>
<input type="radio" name="attendance[<?php echo $row['player_id']; ?>]" value="No" <?php echo set_radio('attendance', 'No'); ?> >Absent
</label>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
public function add()
{
$player_id = $this->input->post('player_id');
$is_present = $this->input->post('attendance');
$i=1;
$data = array();
// formating array posts
foreach ($player_id as $k => $val) {
$data[] = array('player_id' => $val, 'is_present' => $is_present[$i]);
$i++;
}
echo var_dump($data);
}
array(3) {
[0]=>
array(2) {
["player_id"]=>
string(1) "1"
["is_present"]=>
string(3) "Yes"
}
[1]=>
array(2) {
["player_id"]=>
string(1) "2"
["is_present"]=>
string(2) "No"
}
[2]=>
array(2) {
["player_id"]=>
string(1) "3"
["is_present"]=>
string(3) "Yes"
}
}