【发布时间】:2015-08-23 15:44:04
【问题描述】:
我想通过使用 php 复选框将“0”或“1”插入 mysql 数据库,但值无法存储到数据库中! 我试图插入一个这样的复选框数组:
1:选中
0:未选中
[answer] => Array
(
[0] => answer 1
[1] => answer 2
[2] => answer 3
)
[check] => Array
(
[0] => 1
[1] => 0
[2] => 1
)
php 文件:
<td> <!-- <input type="hidden" name="check[]" value="0" >-->
<input type="checkbox" id="check" name="check[]" value="1">
</td>
在通过 AJAX 的进程文件中,我存储了答案数据库,但我无法存储每个选定答案的检查值
$query = mysql_query("INSERT INTO questions
(nom_question,id_categorie)
VALUES('$question','$categorie')", $conn)
or die(mysql_error());
//last insert id question
$last_id = mysql_insert_id();
$check = $_POST['check'];
foreach ($reponse as $key=>$value ) {
$values = mysql_real_escape_string($value);
$x='1';
$query = mysql_query("INSERT INTO reponses
(nom_reponse,id_question,id_categorie,correct)
VALUES ('$values',
'$last_id',
'$categorie',
'$x')")
or die(mysql_error());
请帮忙!如果检查或不检查,我如何存储答案。
【问题讨论】: