question about survey?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

question about survey?

Post by rami »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i was trying make a script for a test program as 
LOGIC IS
i am storing question,4 probable answer (each as field) and a correctans field with corrct answer.
The given answer is comapred with correct answer in database and count is increase by one if correct...

Code: Select all

<?php
$corans[]="";
$ans[]="";
		
		require_once ('connect.php');
		//for question no 1
		$query = "SELECT * from entrance";
		$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
			$i=1;	
		while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) 
		{
			$qno=$row['qno'];
			$ques=$row['question'];
			$op1=$row['posans1'];
			$op2=$row['posans2'];
			$op3=$row['posans3'];
			$op4=$row['posans4'];
			$corans[$i]=$row['corans'];
			echo "<b><br><b>$qno) $ques</b></br><br>";
			echo "(a)<input type=\"radio\" name=\"answer$i\" value=\"$op1\">$op1\t\t";
			echo "(b)<input type=\"radio\" name=\"answer$i\" value=\"$op2\">$op2\t\t";
			echo "(c)<input type=\"radio\" name=\"answer$i\" value=\"$op3\">$op3\t\t";
			echo "(d)<input type=\"radio\" name=\"answer$i\" value=\"$op4\">$op4";		
echo"<br>";
			$i++;
			
		}

<?php
	
	if (isset($_POST['submit'])) 
	{ 

		$count=0;
		for($i=1;$i<=5;$i++)
			{
		$ans[$i]=$_POST['answer$i'];
		if(strcmp($ans[$i],$corans[$i])==0)
		{
			$count++;
		}
		}	
..........
The problem is here

Code: Select all

echo "<b><br><b>$qno) $ques</b></br><br>";
			echo "(a)<input type=\"radio\" name=\"answer$i\" value=\"$op1\">$op1\t\t";
			echo "(b)<input type=\"radio\" name=\"answer$i\" value=\"$op2\">$op2\t\t";
			echo "(c)<input type=\"radio\" name=\"answer$i\" value=\"$op3\">$op3\t\t";
			echo "(d)<input type=\"radio\" name=\"answer$i\" value=\"$op4\">$op4";	
$ans[$i]=$_POST['answer$i'];//THIS IS NOT WORKING	
echo"<br>";
and when doing this
SECOND METHOD USED TO STORE DATA
{

Code: Select all

$count=0;
		for($i=1;$i<=5;$i++)
			{
		$ans[$i]=$_POST['answer$i'];
		if(strcmp($ans[$i],$corans[$i])==0)
		{
IS NOT WORKING EITHER.


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

rami wrote:IS NOT WORKING EITHER.
...doesn mean, there's no output at all(no data is pulled form the database) or wrong/unexpected output or what?
Post Reply