Jump to content

need help answers disappear after i click submit.


cyrixware

Recommended Posts

my page works fine the only problem is that let say for example i have 5 items in the row. every items has its own questions and choices a b c and d. So, if i missed one of the item wen i click submit it will not save to the database instead it will go back or point to the user that he/she should select an answer on that item he/she missed. And the previous answer selected by the user is still there if he/she did not finished select all of the items.

 

i have this code:

<?
include_once("authenticate.php");
$SuID 		= $_REQUEST['SuID'];
$SuCourse 	= $_REQUEST['SuCourse'];
$SCode 		= $_REQUEST['SCode'];
include("../connDB.php");

$sql_search = "SELECT * FROM studans WHERE SubCode = '$SCode' AND SuID = '$SuID'";
$q_search 	= mysql_query($sql_search);
$num_rows 	= mysql_num_rows($q_search);
if( $num_rows != 0 )
{
	?>
	<script language="JavaScript">
		win = window.open('topicareaStudent.php?ID=<?=$session_id;?>&SuID=<?=$SuID;?>&SuCourse=<?=$SuCourse;?>','_self');
		alert("Topic Area = <?=$SCode;?> submitted already!");	
	</script>
	<?
}	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Welcome <?=$r['SuFirstname'];?>! </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="CSSfile.css" rel="stylesheet" type="text/css">
<STYLE type=text/css media=screen>
@import url(student/tanfa.css);
#menu {
FLOAT: left; WIDTH: 100%
}
#menu UL {
PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FLOAT: left; PADDING-BOTTOM: 0px; MARGIN: 0px; WIDTH: 12em; PADDING-TOP: 0px; LIST-STYLE-TYPE: none
}
#menu A {
BORDER-RIGHT: #888 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: #ccc 1px solid; DISPLAY: block; PADDING-LEFT: 3px; PADDING-BOTTOM: 2px; MARGIN: 0px; FONT: bold 11px/16px arial, helvetica, sans-serif; BORDER-LEFT: #bbb 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #555 1px solid
}
#menu H2 {
BORDER-RIGHT: #888; PADDING-RIGHT: 3px; BORDER-TOP: #ccc; DISPLAY: block; PADDING-LEFT: 3px; PADDING-BOTTOM: 2px; MARGIN: 0px; FONT: bold 11px/16px arial, helvetica, sans-serif; BORDER-LEFT: #bbb; PADDING-TOP: 2px; BORDER-BOTTOM: #555}
#menu H2 {
TEXT-TRANSFORM: uppercase;
COLOR: #333333;
border: 1px solid #999999;
}
#menu A {
BACKGROUND: #efefef; COLOR: #000; TEXT-DECORATION: none
}
#menu A:hover {
BACKGROUND: #fff; COLOR: #0066FF}
#menu LI {
POSITION: static;
left: 290px;
top: 89px;
}
#menu UL UL {
Z-INDEX: 500; POSITION: absolute
}
#menu UL UL UL {
LEFT: 100%; POSITION: absolute; TOP: 0px
}
DIV#menu UL UL {
DISPLAY: none
}
DIV#menu UL LI:hover UL UL {
DISPLAY: none
}
DIV#menu UL UL LI:hover UL UL {
DISPLAY: none
}
DIV#menu UL LI:hover UL {
DISPLAY: block
}
DIV#menu UL UL LI:hover UL {
DISPLAY: block
}
DIV#menu UL UL UL LI:hover UL {
DISPLAY: block
}

table {
border:1px solid #000;
border-collapse:collapse;
font-family:verdana;
font-size:50%;
}


td,th{
border:0px solid #000;
border-collapse:collapse;
padding:1px;
background-color:#cccccc;
} 

a:link		{text-decoration:none; color:#000066;}
a:visited	{text-decoration:none; color:#000066;}
a:active	{text-decoration:none; color:#000066;}
a:hover		{text-decoration:none; color:#FF0000;}
.style3 {font-size: 10px}
.style4 {font-size: 12px}
.style13 {font-family: Arial, Helvetica, sans-serif}
.style19 {color: #000066}
<!--
.timeClass {
  font-family:arial,verdana,helvetica,sans-serif;
  font-weight:normal;
  font-size:10pt;
  }
.style22 {font-family: arial,verdana,helvetica,sans-serif; font-weight: normal; font-size: 10pt; color: #FF0000; }
.style23 {color: #FF0000}
-->
</STYLE>
<!--[if IE]>
<STYLE type=text/css media=screen>BODY {
FONT-SIZE: 100%; BEHAVIOR: url(csshover.htc)
}
#menu UL LI {
FLOAT: left; WIDTH: 100%
}
#menu UL LI A {
HEIGHT: 1%
}
#menu A {
FONT: bold 0.7em/1.4em arial, helvetica, sans-serif
}
#menu H2 {
FONT: bold 0.7em/1.4em arial, helvetica, sans-serif
}
</STYLE>
<![endif]-->
<META content="MSHTML 6.00.2900.2604" name=GENERATOR></HEAD>
<body>
<script language="JavaScript">
function form_validator(theForm)
{
if(theForm.studAns[].value == "") {
	 alert("Please enter your choice.");
	 theForm.studAns[].focus();
	 return(false);
}
}
</script>
<form onSubmit="return form_validator(this)" name="form" id="form" method="post" action="topicareaQuiz.php?ID=<?=$session_id;?>&SuID=<?=$SuID;?>&SuCourse=<?=$SuCourse;?>&SCode=<?=$SCode;?>">
<center>
  <div id="container"> 
    <div id="header"> 
      <div id="backimage"> 
        <div id="navbar"> 
          <DIV id="menu">           	
          </DIV>
        </div>
      </div>
    </div>
    <div id="main"> 
      <div id="content1"> 
<?
$SCode		= $_REQUEST['SCode'];
$SuID 		= $_REQUEST['SuID'];
$SuCourse 	= $_REQUEST['SuCourse'];

include("../connDB.php");

$sql_display_students_enrolled = "SELECT * FROM testques WHERE SubCode = '$SCode' ORDER BY RAND()";

$sql_display_students_enrolled1 = "SELECT * FROM subject WHERE SCode = '$SCode'";
$q_display_students_enrolled1 = mysql_query($sql_display_students_enrolled1);

if(!$q_display_students_enrolled = mysql_query($sql_display_students_enrolled))
{
	?>
	<script language="JavaScript">
		win = window.open('topicareaStudent.php?ID=<?=$session_id;?>&SuID=<?=$SuID;?>&SuCourse=<?=$SuCourse;?>','_self');
		alert("Query search result... Unable to display the test questions!");	
	</script>
	<?
}
elseif(mysql_num_rows($q_display_students_enrolled) == 0)
{
	?>
	<script language="JavaScript">
		win = window.open('topicareaStudent.php?ID=<?=$session_id;?>&SuID=<?=$SuID;?>&SuCourse=<?=$SuCourse;?>','_self');
		alert("Query search result... Unable to display the test questions!");	
	</script>
	<?
}
else
{		
?>
<center>
<?
$r_display_students_enrolled1 = mysql_fetch_assoc($q_display_students_enrolled1);
?>
<a name="top"></a>
<table width="61%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td colspan="4"><div align="center"><font color="#000066" size="4" face="Verdana, Arial, Helvetica, sans-serif"></font></div></td>
  </tr>
  <tr> 
    <td colspan="4"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font>      <div align="center"><strong></strong></div></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong></strong></div>      
      <div align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>
            </strong><strong>[</strong></font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong> </strong><span class="style23">
        <?=$r_display_students_enrolled1['SCode'];?> - <?=$r_display_students_enrolled1['SName'];?> 
        </span><strong></strong></font><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>]</strong>
 <strong>  </strong></font></div>
      <hr align="center" width="500">      
      <p> </p>      <div align="center"><strong></strong></div></td>
    </tr>


<?
$x = 0; 	$j = -1;  $tItems = 0;
while($r_display_students_enrolled = mysql_fetch_array($q_display_students_enrolled)){
$x++;
$tItems = $i++;
$j++;
?>
  <tr>
    <td width="16%"><div align="center" class="style13">                <span class="style4"><font color="#000066">
    <span class="style3">
  
    </span>
    <strong>
<? $Item=$r_display_students_enrolled['Item'];
	echo"$x";
?>
).</strong></font> </span></div></td>
    <td colspan="2"><div align="left" class="style13"><strong><font color="#000066" size="2">
             <?=$r_display_students_enrolled['SubQues'];?>
             <strong><font color="#000066" size="2">
             </font></strong> </font> </strong></div></td>
    <td width="3%"> </td>

  </tr>


  <tr>
    <td width="16%"><div align="center" class="style13">                <span class="style4"><font color="#000066">
    <span class="style3">
  
    </span>
    <strong></strong></font></span></div></td>
    <td colspan="2"><div align="left" class="style13"><strong><font color="#000066" size="2">             <strong><font color="#000066" size="2">
             </font></strong> </font> </strong></div></td>
    <td width="3%"> </td>

  </tr> 
  <tr>
    <td rowspan="5">
      <div align="center" class="style13"></div>      <div align="center" class="style13">      </div></td>
    <td width="4%"><div align="left" class="style13"><font color="#000066" size="2"><font color="#000066"><? echo"<input name=studAns[$j] type=radio value=A>";?></font>
      
    </font></div></td>
    <td width="77%"><div align="left" class="style13"><font color="#000066" size="2">
           A. <?=$r_display_students_enrolled['chA'];?>
    </font></div></td>
    <td> </td>
  </tr>
  <tr>
    <td><div align="left" class="style13"><font color="#000066" size="2"><font color="#000066"><? echo"<input name=studAns[$j] type=radio value=B>";?></font> </font></div></td>
    <td><div align="left" class="style13"><font color="#000066" size="2">
          B. <?=$r_display_students_enrolled['chB'];?>
    </font></div></td>
    <td> </td>
  </tr>
  <tr>
    <td><div align="left" class="style13"><font color="#000066" size="2"><font color="#000066"><? echo"<input name=studAns[$j] type=radio value=C>";?></font> </font></div></td>
    <td><div align="left" class="style13"><font color="#000066" size="2">
          C. <?=$r_display_students_enrolled['chC'];?>
    </font></div></td>
    <td> </td>
  </tr>
  <tr>
    <td><div align="left" class="style13"><font color="#000066" size="2"><font color="#000066"><? echo"<input name=studAns[$j] type=radio value=D>";?></font> </font></div></td>
    <td><div align="left" class="style13"><font color="#000066" size="2">
        D. <?=$r_display_students_enrolled['chD'];?>
    </font></div></td>
    <td> </td>
  </tr>
  
  <tr>
    <td height="17"><span class="style13"></span></td>
    <td height="17"><div align="left" class="style13"><span class="style3">  
      <? //	echo"$x";?>      
      <span class="style19">
  <? 
//for($y=0; $y<10; $y++){
  ?>
  <input type="hidden" name="Item[]" value="<?=$r_display_students_enrolled['Item'];?>">
  <? //=$r_display_students_enrolled['Item'];?>
      </span>
        <? //}?>
     <span class="style19">

       <input type="hidden" name="Key[]" value="<?=$r_display_students_enrolled['SubAns'];?>">
       </span></span></div></td>
    <td height="17"> </td>
  </tr>
  <tr>
    <td height="17" colspan="4"><hr align="center" width="500">
      <div align="center"></div></td>
  </tr>
<?

	}
}
  ?>
  <tr>
    <td height="23" colspan="4"><div align="center">
      <div align="center"><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#000066" face="Verdana, Arial, Helvetica, sans-serif"><strong>
        <input type="submit" name="Submit" value="Submit">
      </strong></font></strong></font></strong></font></font></font></font></font></font></strong></font></strong></font></strong></font></font></font></div>
    </div></td>
  </tr>  
</table> 
   	  </div>
    </div>

<div id="footer" align="center"></div>
</div>
</center>
</form>
</body>
</html>
<?
if($_REQUEST['Submit'] == "Submit"){
include("../connDB.php");

$SCode 		= $_REQUEST['SCode'];
$SuID 		= $_REQUEST['SuID'];
$SItems 	= $_REQUEST['Item'];
$SAns 		= $_REQUEST['studAns'];
$SKey 		= $_REQUEST['Key'];

$count      = count($_REQUEST['studAns']);
$varX      	= count($_REQUEST['Key']);
for ($varY 	= $count ; $varY < $varX   ; $varY++)
{ 
	if ((!$_POST[studAns][$varY]) || ($_POST[studAns][$varY] = " "))
	{
	?>
		<script language="JavaScript">
			//win = window.open('topicareaQuiz.php?ID=<?=$session_id;?>&SuID=<? echo"$SuID";?>&SuCourse=<? echo"$SuCourse"; ?>&SCode=<? echo "$SCode";?>','_self');
			alert("Please select answer in every item!");
		</script>
	 <? exit;
	}
}
$sql 		= "SELECT * FROM studans WHERE SubCode = '$SCode' AND SuID = '$SuID' ";
$q_add 		= mysql_query($sql);
$num 		= mysql_num_rows($q_add);
if( $num != 0 )
{
	?>
	<script language="JavaScript">
		win = window.open('topicareaStudent.php?ID=<?=$session_id;?>&SuID=<?=$SuID;?>&SuCourse=<?=$SuCourse;?>','_self');
		alert("Topic Area = <?=$SCode;?> submitted already!");	
	</script>
	<?
}else{
    	$i      = strtoupper(count($_REQUEST['studAns']));
			for ($x = 0 ; $x < $i   ; $x++)
			{ 
				$item++;					
					$sql_add = "INSERT INTO studans ( SuID, 
													  SubCode, 
													  SubItems, 
													  SubKey, 
													  SubAns
													 ) 
													 VALUES 
													 ( '$SuID'," . 
												 		"'" . "$SCode" ."',".
												 		"'" . $_REQUEST['Item'][$x] . "',".
												 		"'" . $_REQUEST['Key'][$x] . "',". 
												 		"'" . $_REQUEST['studAns'][$x] . "')";
					$q_add 	= mysql_query($sql_add);
					if(mysql_affected_rows() == 0)
					{
						echo "<font color=#FF0000 size=2 face=Verdana, Arial, Helvetica, sans-serif><strong>Cannot Save Record at this time try again later...</strong></font>";
					}else
					{
					?>
						<script language="JavaScript">
							win = window.open('topicareaQuiz.do.php?SCode=<? echo "$SCode";?>&SuID=<? echo"$SuID";?>&SuCourse=<?=$SuCourse;?>&tItems=<?=$tItems+1;?>','_self');
							//alert("Processing... Please click OK to submit the exam.");	
						</script>
					<?
					}
			}				
	}
}
?>

Link to comment
Share on other sites

So basically you want to make sure that they have answered every question before they can click submit? Sounds like javascript.

If you want to do it with PHP, you could evaluate all submitted answers on the processing page, and if they left something out, send back to the original question page through GET the values they already submitted, and on the original page, check for these values and then process the questions appropriately (say for instance, placing a SELECTED or selected='selected' in an <option>)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.