我无法使用单选按钮,我不知道插入具有正确答案的值。如果选中,则该值必须为1而另一个为0.这是我的代码:
<form method='post' action='exam.php?act=input' enctype='multipart/form-data'>
<table>
<tr></tr>
<tr>
<td>Nama Exam </td>
<td><input type='text' name='nama_exam'></td>
</tr>
<tr>
<td>Soal </td>
<td><textarea name='soal_exam'></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='radio' name='answer'> <textarea name='option[]'></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='radio' name='answer'> <textarea name='option[]'></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='radio' name='answer'> <textarea name='option[]'></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='radio' name='answer'> <textarea name='option[]'></textarea></td>
</tr>
</table>
<button type='submit'>Submit</button>
</form>
这是插入代码:
<?php
$name = $_POST['nama_exam'];
$exam = $_POST['soal_exam'];
$op = $_POST['option'];
$answer = $_POST['answer'];
//if selected = 1 else = 0
$sql = mysql_query("INSERT INTO `exam`(`exam_name`, `exam`, `exam_entrydate`) VALUES ('$name','$exam',NOW())");
if ($sql){
$v_sql = mysql_query("SELECT * FROM exam order by exam_id DESC limit 1");
$id = mysql_fetch_array($v_soal);
$id_soal = $id['exam_id'];
$pil = count($op);
for($i=0; $i<$pil; $i++){
$sql_pil = mysql_query("INSERT INTO answer (`answer_examcode`,`answer`, `answer_code`,`answer_entrydate`) values ('$id_soal','$op[$i]','$answer',NOW())");
}
echo"
<script language='javascript'>
alert('Data ditambahkan')
document.location='exam.php?act=default'
</script>";
}
答案 0 :(得分:0)
在帖子表单中使用循环来发布数组以插入代码文件:
Uncaught TypeError: undefined is not a function common.es5.js:3062
(anonymous function) common.es5.js:3062
combine common.es5.js:3062
webpackJsonp.../../../common/@angular/common.es5.js common.es5.js:2912
__webpack_require__ bootstrap 7034ec41c5e0cfa2926c:54
webpackJsonp.../../../platform-browser-dynamic/@angular/platform-browser-dynamic.es5.js http.es5.js:2183
__webpack_require__ bootstrap 7034ec41c5e0cfa2926c:54
webpackJsonp.../../../../../src/main.ts environment.ts:8
__webpack_require__ bootstrap 7034ec41c5e0cfa2926c:54
webpackJsonp main.ts:11
__webpack_require__ bootstrap 7034ec41c5e0cfa2926c:54
webpackJsonpCallback bootstrap 7034ec41c5e0cfa2926c:25
(anonymous function) main.bundle.js:1
然后你在插入代码文件中得到这样的数组:
<?php
for($i=1; $i<=4; $i++){
echo "<tr>
<td></td>
<td><input type='radio' value='$i' name='answer'> <textarea name='option[$i]'></textarea></td>
</tr>";
}
?>