我需要创建一个表来注册对机器安全设备进行的维护。
我有一个数据库表,其中包含与自己的安全设备关联的所有机器的列表。
每个安全设备可以为“正常”,“不正常”,“正常”或“不适用”
我用HTML / PHP创建了一个网页,维护人员在该网页上选择要进行维护的机器,这将显示他必须控制和注册设备状态的安全设备列表(好吧,不好...)。
<html>
<? include 'home.php' ?>
<body>
<div>
<form action="insert_controllo.php" method="POST">
<table>
<th>Macchina</th>
<th>Dispositivo</th>
<th>Descrizione</th>
<th>OK</th>
<th>NOK</th>
<th>PARZ</th>
<th>NA</th>
<th>Note</th>
<? while($row = mysql_fetch_array($risultato)){
echo "<tr><td> <input class='hide' type= 'text' name='macc' value ='".$row['macc']."' readonly>
</td><td> <input class='hide' type= 'text' name='iddispssic' value ='".$row['iddispsic']."' readonly>
</td><td> <input class='hide' type= 'text' name='descgen' value ='".$row['descgen']."' readonly>
</td><td> <input type= 'checkbox' name='chk1[]' value ='OK'>
</td><td> <input type= 'checkbox' name='chk1[]' value ='NOK'>
</td><td> <input type= 'checkbox' name='chk1[]' value ='PARZ'>
</td><td> <input type= 'checkbox' name='chk1[]' value ='NA'>
</td><td> <input type='text' name='note' placeholder = 'Note'>
</td></tr>";
}?>
</table>
<button class="bottone" name='submit' type='submit'>Concludi</button>
</form>
</div>
</body>
</html>
我的问题是在POST VAR DUMP中,我仅收到表的第一行
<!-- POST: Array
(
[macc] => 09
[iddispssic] => 2
[descgen] => Ripari Fissi
[chk1] => Array
(
[0] => NOK
)
[note] =>
[submit] =>
)
-->
我不知道如何在选中的复选框中插入数据库
有人可以帮我吗?
我想在数据库中插入类似的内容
机器安全设备状态(确定,不确定,...)-说明(有输入类型的文本在每行上添加注释)-日期时间
答案 0 :(得分:1)
您必须更改输入的名称才能创建元素数组(可以为另一个元素更改“ elements”名称)。
$count = 0;
while($row = mysql_fetch_array($risultato)){
echo '<tr><td> <input class="hide" type= "text" name="elements['.$count.'][macc]" value ="'.$row["macc"].'" readonly>
</td><td> <input class="hide" type= "text" name="elements['.$count.'][iddispssic]" value ="'.$row["iddispsic"].'" readonly>
</td><td> <input class="hide" type= "text" name="elements['.$count.'][descgen]" value ="'.$row["descgen"].'" readonly>
</td><td> <input type= "checkbox" name="elements['.$count.'][chk1][]" value ="OK">
</td><td> <input type= "checkbox" name="elements['.$count.'][chk1][]" value ="NOK">
</td><td> <input type= "checkbox" name="elements['.$count.'][chk1][]" value ="PARZ">
</td><td> <input type= "checkbox" name="elements['.$count.'][chk1][]" value ="NA">
</td><td> <input type="text" name="elements['.$count.'][note]" placeholder = "Note">
</td></tr>';
$count ++;
}
如果同时只允许一个状态,则必须更改复选框以放置单选按钮,如下所示:
$count = 0;
while($row = mysql_fetch_array($risultato)){
echo '<tr><td> <input class="hide" type= "text" name="element['.$count.'][macc]" value ="'.$row["macc"].'" readonly>
</td><td> <input class="hide" type= "text" name="element['.$count.'][iddispssic]" value ="'.$row["iddispsic"].'" readonly>
</td><td> <input class="hide" type= "text" name="element['.$count.'][descgen]" value ="'.$row["descgen"].'" readonly>
</td><td> <input type= "radio" name="element['.$count.'][chk1]" value ="OK">
</td><td> <input type= "radio" name="element['.$count.'][chk1]" value ="NOK">
</td><td> <input type= "radio" name="element['.$count.'][chk1]" value ="PARZ">
</td><td> <input type= "radio" name="element['.$count.'][chk1]" value ="NA" checked>
</td><td> <input type="text" name="element['.$count.'][note]" placeholder = "Note">
</td></tr>';
$count ++;
}
在“ insert_controllo.php”中,您可以通过以下方式读取数据:
if(isset($_POST['elements'])){
for($i=0; $i<count($_POST['elements']); $i++){
// the query. For example 'UPDATE TABLENAME SET chk1 = "'.$_POST['elements']['chk1'].'" WHERE macc = "'.$_POST['elements']['macc'].'" ';
}
}
}