Jump to content

Need Help Please. I loose user input when it reload


jeshrian

Recommended Posts

create_question.php

<?php

session_start();
date_default_timezone_set('Asia/Manila');
if($_SESSION['login']['Ad_UserName']==""||$_SESSION['login']['Ad_QWrite']==""){
@header("Location:error.php");
}elseif($_SESSION['login']['Ad_QWrite']!="1"){
echo "<script type='text/javascript'>alert('You don\'t have rights to access this panel. Please contact the Global Administrator!')</script>";
echo '<script type="text/javascript">history.go(-1)</script>';
}
?>
<?php
if($_SESSION['login']['Ad_QWrite']=="1"){@include("create_question_script.php");};
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr" id="minwidth" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>SRG Administration Panel</title>

<link href="css/images/boss.ico" rel="shortcut icon" type="image/x-icon" />
<script type="text/javascript" src="js/tools.js"></script>
<script type="text/javascript" src="js/validate.js"></script>
<script type="text/javascript" src="js/editor.js"></script>
<script type="text/javascript" src="js/clock.js"></script>

<link rel="stylesheet" type="text/css" href="css/main_import.css" />
<script type="text/javascript" src="js/menu.js"></script>
</head>
<body id="minwidth-body" onLoad="goforit()">



<?php @include("includes/menu.html");?>
 <!---


menubar border STARTS

--->
	<div class="clr"></div>
</div>
<div id="content-box">
	<div class="border">
		<div class="padding">
			<div id="toolbar-box">
   			<div class="t">

			<div class="t">
				<div class="t"></div>
			</div>
		</div>
		<div class="m">


                    
                    
                    
<!---


*********************

title bar menu

*********************


--->   

     
<div class="toolbar" id="toolbar">
  
  
  
  <table class="toolbar"><tr>
    
<!--- form new--->
  <td class="button" >
  <a href="create_question.php"  class="toolbar" onclick="alert('Fill up for the following Information');">
  <span class="addnew32" title="New">  </span>
    New  </a>  </td>
  

  <!--- form Clear All--->
  <td class="button" >
  <a href="create_question.php"  class="toolbar" >
  <span class="clearall32" title="Clear All">  </span>
    Clear All </a>  </td>
  


  <!--- form save--->
    
  <td class="button" >
  <a href="#" onclick="editor1.prepareSubmit();editor2.prepareSubmit();editor3.prepareSubmit(); editor4.prepareSubmit();editor5.prepareSubmit();editor6.prepareSubmit();save_exam_question();" class="toolbar">
  <span class="save32" title="Save">  </span>
    Save  </a>  </td>






  

  <!--- form search--->
    
  <td class="button" >
  <a href="main_question.php" class="toolbar">
  <span class="search32 " title="search">  </span>
    Search  </a>  </td>
  

  

  
<td class="button" >
  <a href="main_question.php" class="toolbar">
  <span class="delete32 " title="Delete">  </span>
    Delete  </a>  </td>

  
<!--- Control Panel---> 
<td class="button" >
  <a href="main.php" class="toolbar">
  <span class="controlpanel32 " title="Control Panel">  </span>
    Control Panel </a>  </td>
  

  
</tr></table>
</div>
<div class="header examquestions48">Create Examination Questions</div>



<div class="clr"></div>
			  </div>

  <div class="b">
					<div class="b">
						<div class="b"></div>
					</div>
				</div>
			</div>
			<noscript></noscript>
		  <div class="clr"> </div>
	  </div>
	</div>
</div>
<div id="border"><div><div></div></div></div>





<!--- Error Message--->
<div class="m" style="margin-bottom:-10px;">
<?php
if ($sw==1){
echo "<div class='errorMessage'><div class='error32'></div>";
echo "<div class='errorTxt'>";
echo "$msg</div></div><br />";
$sw=0;
}
?>
</div>
<!--- End Error Message--->



<!---


Menu Border Ends!

--->

<!--
Mmain Border

--->
<div class="clr"></div>
</div>
<div id="content-box">
	<div class="border">
		<div class="padding">
			<div id="toolbar-box">
   			<div class="t">

			<div class="t">
				<div class="t"></div>
			</div>
		</div>
		<div class="m" style="padding-left:20px; padding-right:20px;">


<br /><div style="font-size:12px"><b>Add Examination Questions</b></div>
<hr /><br />	
    
  
<div style="float:left; width:420px;">
<fieldset> 
<legend><img src="css/images/menubar/square.gif" />Reminders:</legend>
<br />
<b>REMINDERS IN ADDING EXAM QUESTIONS:</b>
<br />• The system allow uploading of pictures for the questions that needs illustration.
<br />• Choose the proper Subject Area and Subject Area Category in making up the questions.
<br />• Typographical error cannot trap by the system, be careful in typing the questions.
<br />• Be sure that the question to be inputted are the questions needed or suited in subject category and subject area.
<br />• Write the description of the uploaded figure at the textboxes.
<br /><br />
</fieldset>
</div>









<!--choose subject category--->
<div style="float:left; width:420px; margin-top:170px; margin-left:-420px;">
<fieldset> 
<legend><img src="css/images/menubar/square.gif" />Subject Category and Subject Category Area:</legend>
<br />
<b>NOTE FOR SUBJECT CATEGORIES AND SUBJECT AREAS:</b>
<br />• The subject categories and subject area available are those subject categories and subject category areas that are avilable in the database. If the question that will be saved is not related to the subject category and subject category, add other category that will be suited to the question that will be added.<br /><br />
<table>
<tr>
<td >

<form  action="<?php echo $_SERVER['PHP_SELF'];?>" method='get'>
Subject Category:
<?php
@include_once("class/class.php");
echo "<select name='subcatChoice' id='subcatChoice' onchange='this.form.submit();'>";

@$db=new DB();
@$db->connect();
$sql="SELECT Cat_ID,Cat_Subject FROM tbl_subjectcategories";
@$array= $db->get_as_array($sql);
if($array==true){
foreach($array as $row){
if ($row[Cat_ID]!=$_GET[subcatChoice]){
	echo "<option value=$row[Cat_ID]>$row[Cat_Subject]</option>";
}else{
	echo "<option selected='selected' value=$row[Cat_ID]>$row[Cat_Subject]</option>";						
}
}
}
@$db->close();
                          
echo "</select>";

?>
</form>
</td>
</tr>






<tr>
<td >

<form method="post" action="create_question.php" name="addQuestions" enctype="multipart/form-data" > 
Category Area:    
<?php
if($_GET['subcatChoice']){
 @include_once("class/class.php");
echo "<select name='subareaChoice' id='subareaChoice'>";
@$db=new DB();
@$db->connect();
$sql="SELECT Cat_Area_ID,Cat_ID,Cat_Area_Name FROM tbl_categoryarea WHERE Cat_ID=$_GET[subcatChoice]";
@$array= $db->get_as_array($sql);
if($array==true){
foreach($array as $row){

if ($row[Cat_ID]!=$_GET[subareaChoice]){

	echo "<option value=$row[Cat_Area_ID]>$row[Cat_Area_Name]</option>";	
}else{

	echo "<option selected='selected' value=$row[Cat_Area_ID]>$row[Cat_Area_Name]</option>";	

}
}



}
@$db->close();
                          
echo "</select>";
}


?>
<input type="hidden" value="<?php echo $_GET[subcatChoice];?>" name="subcatChoice" />
</td>
</tr>

</table>
</fieldset>
</div>  

<!-- end choose subject category--->




<div style="float:left; width:420px; margin-top:350px; margin-left:-420px;">
<fieldset> 
<legend><img src="css/images/menubar/square.gif" /> Examination Question:</legend>
<br />
<b>NOTE FOR EXAMINATION QUESTION:</b>
<br />• Upload pictures if the choices need illustration for examination. The maximum allowable picture upload is 2 pictures.

<br />• Use the editor for editing the text written in the box (Bold, Italic, Underline or even Superscript or Subscript)

<br /><br />



<table>
  

<tr>
<td >
<script type="text/javascript">
    var editor1 = new WYSIWYG_Editor('editor1','<?php echo $_POST[editor1_content];?>');
    editor1.display();
</script>
<div style="margin-top:0px; padding-bottom:10px;">
<b>Figure 1:</b> <input type="file" name="qfig1"/><i> (jpeg format only)</i><br />
<b>Figure 2:</b> <input type="file" name="qfig2"/><i> (jpeg format only)</i><br />


</div>
</td>
</tr>





  
</table>

</fieldset>

</div>  



<div style="float:right; width:480px;">
<fieldset> 
<legend><img src="css/images/menubar/square.gif" />Examination Chioices</legend>
<br />
<b>NOTE FOR EXAMINATION CHOICES:</b>
<br />• Upload pictures if the choices need illustration for examination.
<br />• Use the editor for editing the text written in the box (Bold, Italic, Underline or even Superscript or Subscript)
<br />• The maximum allowable choices for the examination is 5 and the minimum is 4. 
<br />• Check the button that determine the right answer.
<br /><br /> 
<table>

<tr>
<td>
<b>1:</b><input type="radio" name="answerButton" value="1"/>
</td>

<td >
<script type="text/javascript">
    var editor2 = new WYSIWYG_Editor('editor2','<?php echo $_POST[editor2_content];?>');
    editor2.display();
</script>
<div style="margin-top:-10px; padding-bottom:10px;">
<b>Figure 1:</b> <input type="file" name="cfig1" /><i> (jpeg format only)</i></div>
</td>
</tr>


<tr>
<td>
<b>2:</b><input type="radio" name="answerButton" value="2"/>
</td>
<td >
<script type="text/javascript">
    var editor3 = new WYSIWYG_Editor('editor3','<?php echo $_POST[editor3_content];?>');
    editor3.display();
</script>
<div style="margin-top:-10px; padding-bottom:10px;">
<b>Figure 2:</b> <input type="file" name="cfig2"/><i> (jpeg format only)</i></div>
</td>
</tr>
  
  

<tr>
<td>
<b>3:</b><input type="radio" name="answerButton" value="3"/>
</td>
<td >
<script type="text/javascript">
    var editor4 = new WYSIWYG_Editor('editor4','<?php echo $_POST[editor4_content];?>');
    editor4.display();
</script>
<div style="margin-top:-10px; padding-bottom:10px;">
<b>Figure 3:</b> <input type="file" name="cfig3"/><i> (jpeg format only)</i></div>
</td>
</tr>



<tr>
<td>
<b>4:</b><input type="radio" name="answerButton" value="4"/>
</td>
<td >
<script type="text/javascript">
    var editor5 = new WYSIWYG_Editor('editor5','<?php echo $_POST[editor5_content];?>');
    editor5.display();
</script>


<div style="margin-top:-10px; padding-bottom:10px;">
<b>Figure 4:</b> <input type="file" name="cfig4"/><i> (jpeg format only)</i></div>
</td>
</tr>


<tr>
<td>
<b>5:</b><input type="radio" name="answerButton" value="5"/>
</td>
<td >
<script type="text/javascript">
    var editor6 = new WYSIWYG_Editor('editor6','<?php echo $_POST[editor6_content];?>');
    editor6.display();
</script>
<div style="margin-top:-10px; padding-bottom:10px;">
<b>Figure 5:</b> <input type="file" name="cfig5"/><i> (jpeg format only)</i></div>
</td>
</tr>




  </table>
  </fieldset>
  

</form>
</div>



<?php @include ("includes/menu_footer.html");?>









				  <div class="clr"></div>
			  </div>

  <div class="b">
					<div class="b">
						<div class="b"></div>
					</div>
				</div>
			</div>
			<noscript></noscript>
		  <div class="clr"> </div>
	  </div>
	</div>
</div>
<div id="border-bottom"><div><div></div></div></div>

<!---
main Border ENDS
--->   
    
<?php @include("includes/footer.html");?>
















</body>


<!--java script prompting sucessfully added!-->




</html>

create_question_script.php

<?php

session_start();
date_default_timezone_set('Asia/Manila');
if ($_POST){
if ($_POST[subcatChoice]!=""){
if($_POST[subareaChoice]!=""){
if(nl2br(htmlentities($_POST[editor1_content]))!=""){
if($_POST[answerButton]!=""){
if( ($_POST[editor2_content]!="" && $_POST[editor3_content]!="") ){



#determine the answer
if($_POST[answerButton]==1){

$answer= $_POST[editor2_content]; 

}elseif($_POST[answerButton]==2){

$answer=$_POST[editor3_content]; 

}elseif($_POST[answerButton]==3){

$answer=$_POST[editor4_content]; 

}elseif($_POST[answerButton]==4){

$answer=$_POST[editor5_content];  

}elseif($_POST[answerButton]==5){

$answer=$_POST[editor6_content]; } 


@include_once("class/class.php");
$registration=date('Y-n-j');
$admin=$_SESSION[login][Ad_UserName];




#determining if questions contain figure
if($_FILES['qfig1']['size']==""){
$questionFigure1=0;
}else{
$questionFigure1=1;
}



if($_FILES['qfig2']['size']==""){
$questionFigure2=0;
}else{
$questionFigure2=1;
}


#determine if choices contain figure
if($_FILES['cfig1']['size']==""){
$answerFigure=0;
}else{
$answerFigure=1;
}




#determine number of choices
if($_POST[editor4_content]==""){
$noofchoice=2;
}elseif ($_POST[editor5_content]==""){
$noofchoice=3;
}elseif ($_POST[editor6_content]==""){
$noofchoice=4;
}elseif ($_POST[editor6_content]!=""){
$noofchoice=5;
}

#adding information to database
@$db=new DB();
@$db->connect();
$sql="INSERT INTO tbl_questionnaire(Cat_ID,
Cat_Area_ID,
Q_Question,
Q_Choice1,
Q_Choice2,
Q_Choice3,
Q_Choice4,
Q_Choice5,
Q_Answer,
Q_CreatedBy,
Q_DateCreated,
Q_IsQuestionFig1,
Q_IsQuestionFig2,
Q_ChoiceFig,
Q_NoOfAnswer) 																 
    VALUES('$_POST[subcatChoice]',																				'$_POST[subareaChoice]',
'$_POST[editor1_content]', 																		
'$_POST[editor2_content]',    																				'$_POST[editor3_content]',   										 										'$_POST[editor4_content]', 																					'$_POST[editor5_content]',											 										'$_POST[editor6_content]',																							
'$answer',
'$admin',
'$registration',
'$questionFigure1',
'$questionFigure2',
'$answerFigure',
'$noofchoice')";
@$db->add_account($sql);
@$num=mysql_insert_id();
@$id=mysql_insert_id();
@$db->close();






#question figure 1
$source=$_FILES["qfig1"]["tmp_name"];
$target_name1="qfig1_".$num.".jpg";
$target1= "../uploads/examquestions/qfig1/".$target_name1;
@move_uploaded_file($source,$target1);




#question figure 2
$source=$_FILES["qfig2"]["tmp_name"];
$target_name2="qfig2_".$num.".jpg";
$target2= "../uploads/examquestions/qfig2/".$target_name2;
@move_uploaded_file($source,$target2);




#answer figure 1
$source=$_FILES["cfig1"]["tmp_name"];
$target_name3="cfig1_".$num.".jpg";
$target3= "../uploads/examquestions/cfig1/".$target_name3;
@move_uploaded_file($source,$target3);





#answer figure 2
$source=$_FILES["cfig2"]["tmp_name"];
$target_name4="cfig2_".$num.".jpg";
$target4= "../uploads/examquestions/cfig2/".$target_name4;
@move_uploaded_file($source,$target4);




#answer figure 3
$source=$_FILES["cfig3"]["tmp_name"];
$target_name5="cfig3_".$num.".jpg";
$target5= "../uploads/examquestions/cfig3/".$target_name5;
@move_uploaded_file($source,$target5);




#answer figure 4
$source=$_FILES["cfig4"]["tmp_name"];
$target_name6="cfig4_".$num.".jpg";
$target6= "../uploads/examquestions/cfig4/".$target_name6;
@move_uploaded_file($source,$target6);



#answer figure 5
$source=$_FILES["cfig5"]["tmp_name"];
$target_name7="cfig5_".$num.".jpg";
$target7= "../uploads/examquestions/cfig5/".$target_name7;
@move_uploaded_file($source,$target7);

#update database for questions
@$db=new DB();
@$db->connect();
$sql="UPDATE tbl_questionnaire SET 
Q_Fig1='$target_name1',											
Q_Fig2='$target_name2' ,																			
Q_ChoiceFig1='$target_name3',																	
Q_ChoiceFig2='$target_name4',												
Q_ChoiceFig3='$target_name5',													
Q_ChoiceFig4='$target_name6',
Q_ChoiceFig5='$target_name7' 																					
WHERE Q_ID='$id'";
@$db->add_account($sql);
@$db->close();

echo "<script type='text/javascript'>window.location='main_question.php?popup=1';</script>";


}else{
$msg="Please fill up at least 2 answers!";$sw=1;}
}else{
$msg="Please select for the right answer!";$sw=1;}
}else{
$msg="Please input the question!";$sw=1;}	
}else{
$msg="Please select Subject Area Category!";$sw=1;}	
}else{
$msg="Please select Subject Category!";$sw=1;}	



}






?>

 

 

Guys, masters, fellow users, I really need a help here

 

These are two files of code to create a question for an exam. all the code is working and its function.

except when error handling shows up, for example when user forgots to choose answer, category, subjectcategory, and etc

when it catches the error it will load again and loose all the previous user inputs

         

I know its in my logic on programming, please help me find a solution to avoid reloading of page and loosing user inputs

 

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.