Hi guys, basically here pull out the data from database then creating taxt field automatically and submit into anther table. everything works fine but data not inserting in to the table. could you guys check my code please?
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error());
?>
<?php
$result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error());
echo '<select name ="cid[]">';
while($row = mysql_fetch_array($result))
{
echo '<option value="' . $row['CourseID'] . '">'. $row['CourseID'] .'</option>';
}
echo '</select>';
//------------------
?>
<?php
if(!empty($_POST["submit"]))
{
$value = empty($_POST['question']) ? 0 : $_POST['question'];
?>
<form name="form1" method="post" action="result.php">
<?php
for($i=0;$i<$value;$i++)
{
echo 'Question NO: <input type="text" name="qno[]" size="2" maxlength="2" class="style10">
Enter Marks: <input type="text" name="marks[]" size="3" maxlength="3" class="style10"><br>';
}
?>
<label> <br />
<br />
<input type="submit" name="Submit" value="Submit" class="style10">
</label>
</form>
<?php
}
else{
?>
<form method="POST" action="#">
<label>
<span class="style10">Enter the Number of Question</span>
<input name="question" type="text" class="style10" size="2" maxlength="2">
</label>
<input name="submit" type="submit" class="style10" value="Submit">
</form>
<?php }?>
result.php
<?php
$con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error());
mysql_select_db("uni",$con) or die('Could not connect: ' . mysql_error());
foreach ($_POST['cid'] as $c) {$cid [] = $c;}
foreach($_POST['qno'] as $q){$qno[] = $q;}
foreach($_POST['marks'] as $m){$marks[] = $m;}
$ct = 0;
for($i=0;$i<count($qno);$i++)
{
$sql="INSERT INTO examquesion (CourseID,QuesionNo,MarksAllocated) VALUES('$cid[$i]','$qno[$i]','$marks[$i]')";
mysql_query($sql,$con) or die('Error: ' . mysql_error());
$ct++;
}
echo "$ct record(s) added";
mysql_close($con)
?>