สวัสดีครับ
คือผมสร้างแบบทดสอบด้วยภาษา php แต่พออัพขึ้นเซิร์ฟเวอร์จริงคะแนนออกเป็น 0 อะครับ
ไฟล์ที่ 1
<form name="form1" method="post" action="test_ans.php">
<?
$host="localhost";
$username="technology_db";
$password="1DumqkmpS5";
$db="technology_db";
$tb="testing";
mysql_connect( $host,$username,$password) or die (" NO Mysql");
mysql_select_db($db) or die("NO");
$sql="SELECT * FROM testing order by rand() limit 10";
$db_query=mysql_query($sql);
$i=0;
while($result=mysql_fetch_array($db_query))
{
$i++;
?>
<table border="0" align="center" >
<tr>
<td width="129"><div >
<h3>
<input name="id_ques[<?=$i;?>]" type="hidden" value="<?=$result["id_ques"];?>">
<?=$result["question"];?>
</h3>
</div></td>
</tr>
<tr>
<td><input name="c<?=$i;?>" type="radio" value="1" />
<?=$result["c1"];?></td>
</tr>
<tr>
<td><input type="radio" name="c<?=$i;?>" value="2" />
<?=$result["c2"];?></td>
</tr>
<tr>
<td><input type="radio" name="c<?=$i;?>" value="3" />
<?=$result["c3"];?></td>
</tr>
<tr>
<td><input type="radio" name="c<?=$i;?>" value="4" />
<?=$result["c4"];?>
<input name="ans[<?=$i;?>]" type="hidden" value="<?=$result["ans"];?>" /></td>
</tr>
<tr>
<td><center>
<img src="images/bar2.png" width="597" height="1">
</center>
</td>
</tr>
</table><?
}
mysql_close();
?>
<div align="center"><br>
<input type="hidden" name="line" value="<?=$i;?>">
<input type="submit" name="Submit" value="ตรวจคะแนน">
</div>
</form>
ไฟล์ test_ans.php
<?
$score=0;
for($i=1;$i<=$_POST["line"];$i++)
{
if($_POST["c$i"] == $_POST["ans$i"])
{
$score=$score+1;
}
}
echo "True $score<br>";
?>
รบกวนช่วยหน่อยนะครับ
PHP แบบทดสอบอัพขึ้นเซิร์ฟเวอร์แล้วคะแนนเป็น 0
คือผมสร้างแบบทดสอบด้วยภาษา php แต่พออัพขึ้นเซิร์ฟเวอร์จริงคะแนนออกเป็น 0 อะครับ
ไฟล์ที่ 1
<form name="form1" method="post" action="test_ans.php">
<?
$host="localhost";
$username="technology_db";
$password="1DumqkmpS5";
$db="technology_db";
$tb="testing";
mysql_connect( $host,$username,$password) or die (" NO Mysql");
mysql_select_db($db) or die("NO");
$sql="SELECT * FROM testing order by rand() limit 10";
$db_query=mysql_query($sql);
$i=0;
while($result=mysql_fetch_array($db_query))
{
$i++;
?>
<table border="0" align="center" >
<tr>
<td width="129"><div >
<h3>
<input name="id_ques[<?=$i;?>]" type="hidden" value="<?=$result["id_ques"];?>">
<?=$result["question"];?>
</h3>
</div></td>
</tr>
<tr>
<td><input name="c<?=$i;?>" type="radio" value="1" />
<?=$result["c1"];?></td>
</tr>
<tr>
<td><input type="radio" name="c<?=$i;?>" value="2" />
<?=$result["c2"];?></td>
</tr>
<tr>
<td><input type="radio" name="c<?=$i;?>" value="3" />
<?=$result["c3"];?></td>
</tr>
<tr>
<td><input type="radio" name="c<?=$i;?>" value="4" />
<?=$result["c4"];?>
<input name="ans[<?=$i;?>]" type="hidden" value="<?=$result["ans"];?>" /></td>
</tr>
<tr>
<td><center>
<img src="images/bar2.png" width="597" height="1">
</center>
</td>
</tr>
</table><?
}
mysql_close();
?>
<div align="center"><br>
<input type="hidden" name="line" value="<?=$i;?>">
<input type="submit" name="Submit" value="ตรวจคะแนน">
</div>
</form>
ไฟล์ test_ans.php
<?
$score=0;
for($i=1;$i<=$_POST["line"];$i++)
{
if($_POST["c$i"] == $_POST["ans$i"])
{
$score=$score+1;
}
}
echo "True $score<br>";
?>
รบกวนช่วยหน่อยนะครับ