i have following script.
problems i want to add answers to database from admin side with iscorrect option.if type is multiple it can have multiple answers so multiple checkbox will be selected and those are are iscorrect options add as 1 to the db and those are nt checked are 0 in db.

i am not able to access checkbox array they are not getting accessed.

accessed bt prblm is that if i checked 1st and 3rd then values must be 1 0 1
bt it storing 1 1 0

2nd problem

when the select type is objective then allow user to check only one checkbox to check iam nt able to do that.


so please help me anyone as my whole project is stopped here.


<?php
session_start();
require("../database.php");
include("header.php");
?>

<?php
extract($_POST);

echo "<BR>";
if (!isset($_SESSION[alogin]))
{
echo "<br><h2><div class=head1>You are not Logged On Please Login to Access this Page</div></h2>";
echo "<a href=index.php><h3 align=center>Click Here for Login</h3></a>";
exit();
}
echo "<BR><h3 class=head1>Add Question </h3>";
if($_POST[submit]=='Save' || strlen($_POST['testid'])>0 )
{

extract($_POST);
//query to insert data in question table
$result=mysql_query("insert into mst_question(que_id,test_id,que_desc,isMultiple) values ('','$testid','$que','$quetype')",$cn) or die(mysql_error());
$cnt=$cnt+1;
$query = "select MAX(que_id) from mst_question";
$result = mysql_query($query);
$data = mysql_fetch_array($result);
$quemax= $data[0];

//query to insert data in answer table


$count=count($addans1);
//print_r($t);
$arr=$_GET['$t'];
//print_r(count($_POST['t']));

for($cnt=0;$cnt<$count;$cnt++)
{
if($t[$cnt]=='true')
{
$correct=1;
}
else
{
$correct=0;
}
mysql_query("insert into mst_answer(que_id,ans_desc,is_Correct) values ('$quemax','$addans1[$cnt]','$correct')",$cn) or die(mysql_error());

}

echo "<p align=center> Question Added Successfully.</p>";
unset($_POST);
}
?>
<script type="text/javascript">
function check() {
mt=document.form1.que.value;
if (mt.length<1) {
alert("Please Enter Question");
document.form1.que.focus();
return false;
}
return true;
} </script>

<form name="form1" method="post" onSubmit="return check();">
<table width="80%" border="0" align="center">
<tr>
<td width="24%" height="32"><div align="left"><strong>Select Test Name </strong></div></td>
<td width="1%" height="5">
<td width="85%" height="32">
<select name="testid" id="testid">
<option selected="selected" name="testid">Select</option>
<?php
$rs=mysql_query("Select * from mst_test order by test_name",$cn);
while($row=mysql_fetch_array($rs))
{
if($row[0]==$testid)
{
echo "<option value='$row[0]' >$row[1]</option>";
}
else
{
echo "<option value='$row[0]' >$row[1]</option>";
}
}
?>
</select></td></tr>
<tr>
<td><strong>Question Type</strong></td>
<td width="1%" height="5">
<td width="85%" height="32">
<select name="quetype" id="quetype" onchange="display(this)">
<option selected="selected">Select</option>
<option value="1" >Multiple</option>
<option value="0">Objective</option>
<option value="0" >True/False</option>
</select></td>
</tr>
<tr>
<td height="26"><div align="left"><strong> Enter Question </strong></div></td>
<td>&nbsp;</td>
<td><div id="no"></div><textarea name="que" cols="60" rows="2" id="que"></textarea></td>


</tr>
<tr>
<td valign="top"><strong>Enter Answer </strong></td>
<td height="5"></td>
<td>
<div id="opt1" name="opt1">
</div>
<div id="ft" name="ft">
</div>
</td>
<script type="text/javascript">

var i=1;
function addans()
{
{
document.getElementById('opt1').innerHTML=document.getElementById('opt1').innerHTML+'<br><input type="checkbox" name="t[]" value="true" id="+i+" onclick="check11()"><textarea name="addans1[]" cols="60" rows="2" id="addans1" ></textarea>';
}
i++;
}

function display(obj)
{
var c = document.getElementById('adans');
document.getElementById('opt1').innerHTML = '';
if(obj.selectedIndex == 3)
{
c.style.visibility = 'hidden';
document.getElementById('opt1').innerHTML=document.getElementById('opt1').innerHTML+'<br><input type="radio" name="tr" value="true">'+'True<br><input type="radio" name="tr" value="false">False';
}
else
{
c.style.visibility='visible';
}
}

function check11()
{
var c = document.getElementsByName('quetype');
if(c.selectedIndex==2)
{
var count = 0;
var checkBoxes = document.getElementsByTagName('input');

for (var index = 0; index < checkBoxes.length; index++)
{
if (checkBoxes[index].type == 'checkbox')
{
if (!checkBoxes[index].disabled)
{
count = checkBoxes[index].checked ? (count + 1) : count;
}
}
}

if (count > 1)
{
alert('Maximum of one checkboxes only can be selected');
return false;
}
return true;
// var numbers = new Array();
////for (i = 0; i < document.form1.t.length; i++)
////{
////numbers[i] = document.form1.t[i].value;
////}
////alert("hi"+numbers[0]);
//}

</script>

</tr>
<tr>
<td colspan="3" align="center"> <input value="Add Answer" type="button" onclick="addans()" id="adans" /> </td>
</tr>
<tr>
<td height="26"></td>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Submit" ></td>
</tr>
</table>
</form>