我编写此代码以从用户那里获取任务及其否
<form method="POST" action="add.php">
<tr> <td colspan="4">Tasks</td> </tr>
<tr>
<td colspan="4">
<div id="tasksInput">
Task Name<input type="text" name="mytasks[]"/>
No <input type="text" name="myvol[]"/>
<input type="button" value="add" onClick="add('tasksInput');">
</div>
</td> </tr>
<input type="submit"/> </form>
Java脚本“tasksInput”函数是
<script type="text/javascript">
var count = 1;
var limitt = 100;
function add(divName2){
if (count == limitt) {
alert("You have reached the limit of adding " + count + " inputs");
}
else {
var newdiv2 = document.createElement('div');
newdiv2.innerHTML = "Task " + (count + 1) + " <input type='text' name='mytask[]'>" + "No <input type='text' name='myvol[]'/>";
document.getElementById(divName2).appendChild(newdiv2);
count++;
}
}
</script>
当我点击提交时,他必须将任务存储在数据库中,假设我将存储 A 1 B 2 C 3
在DB中,他将只存储任务B和C以及第1、2号你能帮我吗?
这是我的php代码
$needs=$_POST['mytask'];
$no=$_POST['myvol'];
$N = count($needs);
if(! empty($_POST['mytask']))
{
for($i=0; $i < $N; $i++)
{
$needname = $needs[$i];
$noneed= $no[$i];
if(! empty($needname ))
{
$query2=mysql_query("INSERT INTO projecttasks VALUES('','','$needname',' $noneed','')");
}
}
}