Jump to content

php code working on local server but not on public server


flunn

Recommended Posts

I have a page on my website which includes a form-based quiz, coded in php, that works properly on my local (MAMP) server but not on my public server.

 

The quiz is supposed to work in the following way:

The user answers the questions by typing into text boxes and then clicks on a “submit” button. The quiz reappears with the answers intact but with the background colors of the text boxes changed to green or red depending on whether the questions are answered correctly or incorrectly. This works properly on the local server, but on the public server, the first time the button is clicked, the quiz simply reappears without the background colors changed. When the button is clicked for a second time, everything works as it’s supposed to and continues to do so until the browser is closed. When the browser is reopened, the problem reappears.

 

I have contacted the support people at the public server but they have been no help so far.

 

Any ideas on what might be causing this or on how it might be fixed would be much appreciated.

 

regards to all from flunn

Link to comment
Share on other sites

Thank you, Ignace, for your reply. I am posting the code as you requested.

 

First the header:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>
		<?php
	if (defined ('TITLE')) {
		print TITLE;
	}else{
		print 'flesl.net - ESL materials';
	}
	?>
	</title>
	<script type="text/javascript" src="swfobject.js"></script>

	<link  rel ="stylesheet" type = "text/css" href = "tense_quiz_styles.css" media="all" />
	<style type="text/css">
		p a {
		text-decoration: underline;
		color:black;
		}
		p a:hover {
		color:black;
		text-decoration: underline;
		}
		p a:visited {
		color:black;
		text-decoration: underline;
		}
		.comment{
		width: 524px;
		margin-left: auto;
		margin-right: auto;
		margin-top:-6px;
		margin-bottom: 25px;
		font-style: italic;
		}
		.hi-lite{
		padding: 2px;
		border: 2px solid #0099FF;
		background:#CCFFFF;
		}
		.light_hi-lite{
		padding: 2px;
		border: 1px solid #0099FF;
		}
		.normal_space{
		word-spacing:1px;
		}
		.plus_top{
		margin-top:14px;
		}
		h2 {
		margin-left:0px;
		}
		.instructions{
		color:black;
		text-indent: -.5em;
		margin-left: 10px;
		font-size: 12px;
		line-height: 140%;
		margin-bottom: 5px;
		}
		.bold{
		font-weight: bold;
		}
		.instructions2{
		margin-top:-3px;
		color:black;
		margin-left: 15px;
		font-size: 11px;
		}
		#instruction_box{
		border: none;
		top: 35px;
		margin-left:0px;

		}
		#exercise_box{

		}
	</style>
</head>
<body>
	<!--[if IE 6]>
	<div id="IEroot">
	<![endif]-->
	<div id="new_wrapper">
		<div id="banner_box">
			<div id="banner_topLeft">
			<?php
			print '<h1 class="gray">';
			print $title ;
			print '</h1>';				
			?>
			</div> <!--banner_topLeft-->
			<div id="banner_topRight">
				<h2 class="banner_text"> <a href ="../new_home.html">home</a> &#8226; <a href ="../Directories/reading_directory.html">reading</a> &#8226;  <a href ="../Directories/grammar_directory.html">grammar</a> &#8226;    <a href ="../Directories/vocab_directory.html">vocab</a> &#8226; <a href ="../Directories/listening_directory.html">listening</a> &#8226;  <a href ="../Directories/speaking_directory.html">speaking</a> &#8226; <a href ="../Directories/writing_directory.html">writing</a> &#8226; <a href ="../Directories/activities_directory.html">activities</a> 
				</h2>
			</div> <!--banner_topRight_alt-->
			<div id="banner_bottomLeft">
			<?php
			print '<h1 class="fourteen gray">';
			print $sub_title ;
			print '</h1>';				
			?>
			</div><!--banner_bottomLeft-->
			<div id="banner_bottomRight">
				<h2 class="banner_text_bottom"><a href ="<?php print $local1;?>"><?php print $local1txt;?></a>  <a href ="<?php print $local2;?>"><?php print $local2txt;?></a>  <a href ="<?php print $local3;?>"><?php print $local3txt;?></a>  &#8226;    <a href ="<?php print $local4;?>"><?php print $local4txt;?></a>  &#8226;   <a href ="<?php print $local5;?>"><?php print $local5txt;?></a>
				</h2>
			</div><!--banner_bottomRight-->
			<div id="logo_box">
<!--<img src="http://www.flesl.net/Stories/Series2/flesl_logo(ps).jpg" alt="logo"/>//localhost:8888/flesl-->
				<img src="g_logo_5.jpg" alt="grammar_logo"/>


			</div> <!--logo-->
		</div> <!--banner-->

 

 

And here is the rest of the code

 

 <?php 
session_start(); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
$title="verb tense quiz";
$sub_title="simple past &<br/>present perfect";

$local3="about_tense_quizzes.php";
$local3txt="<span class=\"small_spacing\">about the tense quizzes</span>";
$local4="about_this_quiz.php";
$local4txt="<span class=\"small_spacing\">about this quiz</span>";
$local5txt="printable";


$start1= "\"I ";
$end1=" an ad for this new movie, <span class=\"italic\">One for the Money,</span> in the paper this morning,\" Harry said to Jill at lunch. \"Do you know anything about it?\"";
$correct1="saw";

$start2= "\"I certainly do,\" said Jane with a big smile. \"I  ";
$end2=" it three times already. I think it's great!\"";
$correct2="have seen";

$start3= "\"By the way,\" said Harry a bit later, \"I ";
$end3=" Jack at <span class=\"italic\">Pedro's</span> last night.\"";
$correct3="saw";

$start4= "\"Was he by himself?\" Jill asked. \"Jane told me she ";
$end4=" him with Sally quite often recently.\"";
$correct4="has seen";

$start5= "\"Well, this time he was with Suzie,\" said Harry. \"She ";
$end5=" me when they came in and gave me a big smile.\"";
$correct5="saw";

$start6= "\"I'm pretty sure he ";
$end6=" me too, but he pretended not to.\"";
$correct6="saw";

$start7= "\"That's typical,\" said Jill. \"I ";
$end7=" him do that sort of thing many times. He seems to think he can make himself invisible by not looking at you.\"";
$correct7="have seen";

$start8= "Harry took a sip of his drink, looked at Jill, and said, \"Let's change the subject. I ";
$end8="Ted's report on <span class=\"italic\"> NewStart</span> on your desk earlier.\"";
$correct8="saw";

$start9= "And Jill replied, \"It looks fine to me, but I don't know if Jeremy ";
$end9=" it yet. He's the one everything depends on.\"";
$correct9="has seen";

$start10= "Jill and Harry walked most of the way back to the office in silence. When they were nearly there, Jilll suddenly said, \"Harry, I've decided to get a divorce. I ";
$end10=" my lawyer.";
$correct10="have seen";


require('tense_quiz_header.html');

print '<div id="content_box">';
print '<h2>Verb Tense Quiz 4: Simple Past & Present Perfect</h2>';
print '<form action="tense_quiz_4.php" method="post">';//START OF FORM

print '<div id="instruction_box">';
print '<p class= "instructions bold">INSTRUCTIONS:</p>';
print '<p class= "instructions2">&#8226; TYPE THE <span class="bold">SIMPLE PAST</span> OR THE <span class="bold">PRESENT PERFECT</span> OF <span class="bold">"SEE"</span> IN EACH OF THE BOXES.</p>';
print '</div>'; //instruction_box

print '<div id="exercise_box">';

//LOOP TO CHECK WHETHER ALL THE QUESTIONS HAVE BEEN ANSWERED
foreach ($_POST as $value){
if (!empty ($value)){
$done++;
}
}

//QUESTION ONE
//if button has not been clicked
if(!isset ($_POST['answer1'])){
print '<p> (1) '; 
print $start1;
print '<input class = "white_back" type="text" name="answer1" size="10" value="'.$_POST['answer1'].'" />';
print $end1;
print '</p>';
}
//if button has been clicked but this question has not been answered
elseif (empty($_POST['answer1'])){
print '<p>(1) ';
print $start1;
print '<input class= "yellow_back" type="text" name="answer1" size="10" value="'.$_POST['answer1'].'" />';
print $end1;
print '</p>';
}
//if all questions have been answered
elseif ($done==11){
if (($_POST['answer1'])==$correct1){
$_SESSION['answer1']="right";
$score++;
print '<p> (1) '; 
print $start1;
print '<input class = "green_back" type="text" name="answer1" size="10" value="'.$_POST['answer1'].'" />';
print $end1;
print '</p>';
}else{
$_SESSION['answer1']="wrong";
print '<p> (1) '; 
print $start1;
print '<input class = "red_back" type="text" name="answer2" size="10" value="'.$_POST['answer1'].'" />';
print $end1;
print '</p>';
}
}
//if not all questions have been answered but this one has
else{
print '<p> (1) '; 
print $start1;
print '<input class="white_back" type ="text" name="answer1" size="10" value="'.$_POST['answer1'].'" />';
print $end1;
print '</p>';
}

//QUESTION TW0
if(!isset ($_POST['answer2'])){
print '<p> (2) '; 
print $start2;
print '<input class="white_back" type="text" name="answer2" size="10" value="'.$_POST['answer2'].'" />';

print $end2;
print '</p>';
}
elseif (empty($_POST['answer2'])){
print '<p>(2) ';
print $start2;
print '<input class= "yellow_back" type="text" name="answer2" size="10" value="'.$_POST['answer2'].'" />';
print $end2;
print '</p>';

}
elseif ($done==11){
if (($_POST['answer2'])==$correct2){
$_SESSION['answer2']="right";
$score++;
print '<p> (2) '; 
print $start2;
print '<input class = "green_back" type="text" name="answer2" size="10" value="'.$_POST['answer2'].'" />';
print $end2;
print '</p>';
}else{
$_SESSION['answer2']="wrong";
print '<p> (2) '; 
print $start2;
print '<input class = "red_back" type="text" name="answer2" size="10" value="'.$_POST['answer1'].'" />';
print $end2;
print '</p>';
}
}
else{
print '<p> (2) '; 
print $start2;
print '<input class="white_back" type="text" name="answer2" size="10" value="'.$_POST['answer2'].'" />';
print $end2;
print '</p>';
}



//QUESTION THREE
if(!isset ($_POST['answer3'])){
print '<p> (3) '; 
print $start3;
print '<input class= "white_back" type="text" name="answer3" size="10" value="'.$_POST['answer3'].'" />';
print $end3;
print '</p>';
}
elseif (empty($_POST['answer3'])){
print '<p>(3) ';
print $start3;
print '<input class= "yellow_back" type="text" name="answer3" size="10" value="'.$_POST['answer3'].'" />';
print $end3;
print '</p>';

}
elseif ($done==11){
if (($_POST['answer3'])==$correct3){
$_SESSION['answer3']="right";
$score++;
print '<p> (3) '; 
print $start3;
print '<input class = "green_back" type="text" name="answer3" size="10" value="'.$_POST['answer3'].'" />';
print $end3;
print '</p>';
}else{
$_SESSION['answer3']="wrong";
print '<p> (3) '; 
print $start3;
print '<input class = "red_back" type="text" name="answer3" size="10" value="'.$_POST['answer3'].'" />';
print $end3;
print '</p>';
}
}
else{
print '<p> (3) '; 
print $start3;
print '<input class="white_back" type="text" name="answer3" size="10" value="'.$_POST['answer3'].'" />';
print $end3;
print '</p>';
}

//QUESTION FOUR
if(!isset ($_POST['answer4'])){
print '<p> (4) '; 
print $start4;
print '<input class="white_back" type="text" name="answer4" size="10" value="'.$_POST['answer4'].'" />';
print $end4;
print '</p>';
}
elseif (empty($_POST['answer4'])){
print '<p>(4) ';
print $start4;
print '<input class= "yellow_back" type="text" name="answer4" size="10" value="'.$_POST['answer4'].'" />';
print $end4;
print '</p>';

}
elseif ($done==11){
if (($_POST['answer4'])==$correct4){
$_SESSION['answer4']="right";
$score++;
print '<p> (4) '; 
print $start4;
print '<input class = "green_back" type="text" name="answer3" size="10" value="'.$_POST['answer4'].'" />';
print $end4;
print '</p>';
}else{
$_SESSION['answer4']="wrong";
print '<p> (4) '; 
print $start4;
print '<input class = "red_back" type="text" name="answer4" size="10" value="'.$_POST['answer4'].'" />';
print $end4;
print '</p>';
}
}
else{
print '<p> (4) '; 
print $start4;
print '<input class="white_back" type="text" name="answer4" size="10" value="'.$_POST['answer4'].'" />';
print $end4;
print '</p>';
}

//QUESTION FIVE
if(!isset ($_POST['answer5'])){
print '<p> (5) '; 
print $start5;
print '<input class="white_back" type="text" name="answer5" size="10" value="'.$_POST['answer5'].'" />';
print $end5;
print '</p>';
}
elseif (empty($_POST['answer5'])){
print '<p>(5) ';
print $start5;
print '<input class= "yellow_back" type="text" name="answer5" size="10" value="'.$_POST['answer5'].'" />';
print $end5;
print '</p>';

}
elseif ($done==11){
if (($_POST['answer5'])==$correct5){
$_SESSION['answer5']="right";
$score++;
print '<p> (5) '; 
print $start5;
print '<input class = "green_back" type="text" name="answer5" size="10" value="'.$_POST['answer5'].'" />';
print $end5;
print '</p>';
}else{
$_SESSION['answer5']="wrong";
print '<p> (5) '; 
print $start5;
print '<input class = "red_back" type="text" name="answer5" size="10" value="'.$_POST['answer5'].'" />';
print $end5;
print '</p>';
}
}
else{
print '<p> (5) '; 
print $start5;
print '<input class="white_back" type="text" name="answer5" size="10" value="'.$_POST['answer5'].'" />';
print $end5;
print '</p>';
}

//QUESTION SIX
if(!isset ($_POST['answer6'])){
print '<p> (6) '; 
print $start6;
print '<input class="white_back" type="text" name="answer6" size="10" value="'.$_POST['answer6'].'" />';
print $end6;
print '</p>';
}
elseif (empty($_POST['answer6'])){
print '<p>(6) ';
print $start6;
print '<input class= "yellow_back" type="text" name="answer6" size="10" value="'.$_POST['answer6'].'" />';
print $end6;
print '</p>';

}
elseif ($done==11){
if (($_POST['answer6'])==$correct6){
$_SESSION['answer6']="right";
$score++;
print '<p> (6) '; 
print $start6;
print '<input class = "green_back" type="text" name="answer6" size="10" value="'.$_POST['answer6'].'" />';
print $end6;
print '</p>';
}else{
$_SESSION['answer6']="wrong";
print '<p> (6) '; 
print $start6;
print '<input class = "red_back" type="text" name="answer6" size="10" value="'.$_POST['answer6'].'" />';
print $end6;
print '</p>';
}
}
else{
print '<p> (6) '; 
print $start6;
print '<input class="white_back" type="text" name="answer6" size="10" value="'.$_POST['answer6'].'" />';
print $end6;
print '</p>';
}
//QUESTION SEVEN
if(!isset ($_POST['answer7'])){
print '<p> (7) '; 
print $start7;
print '<input class="white_back"  type="text" name="answer7" size="10" value="'.$_POST['answer7'].'" />';
print $end7;
print '</p>';
}
elseif (empty($_POST['answer7'])){
print '<p>(7) ';
print $start7;
print '<input class= "yellow_back" type="text" name="answer7" size="10" value="'.$_POST['answer7'].'" />';
print $end7;
print '</p>';

}
elseif ($done==11){
if (($_POST['answer7'])==$correct7){
$_SESSION['answer7']="right";
$score++;
print '<p> (7) '; 
print $start7;
print '<input class = "green_back" type="text" name="answer7" size="10" value="'.$_POST['answer7'].'" />';
print $end7;
print '</p>';
}else{
$_SESSION['answer7']="wrong";
print '<p> (7) '; 
print $start7;
print '<input class = "red_back" type="text" name="answer7" size="10" value="'.$_POST['answer7'].'" />';
print $end7;
print '</p>';
}
}
else{
print '<p> (7) '; 
print $start7;
print '<input class="white_back" type="text" name="answer7" size="10" value="'.$_POST['answer7'].'" />';
print $end7;
print '</p>';
}

//QUESTION EIGHT
if(!isset ($_POST['answer8'])){
print '<p> ( '; 
print $start8;
print '<input class="white_back" type="text" name="answer8" size="10" value="'.$_POST['answer8'].'" />';
print $end8;
print '</p>';
}
elseif (empty($_POST['answer8'])){
print '<p>( ';
print $start8;
print '<input class= "yellow_back" type="text" name="answer8" size="10" value="'.$_POST['answer8'].'" />';
print $end8;
print '</p>';

}
elseif ($done==11){
if (($_POST['answer8'])==$correct5){
$_SESSION['answer8']="right";
$score++;
print '<p> ( '; 
print $start8;
print '<input class = "green_back" type="text" name="answer8" size="10" value="'.$_POST['answer8'].'" />';
print $end8;
print '</p>';
}else{
$_SESSION['answer8']="wrong";
print '<p> ( '; 
print $start8;
print '<input class = "red_back" type="text" name="answer8" size="10" value="'.$_POST['answer8'].'" />';
print $end8;
print '</p>';
}
}
else{
print '<p> ( '; 
print $start8;
print '<input class="white_back" type="text" name="answer8" size="10" value="'.$_POST['answer8'].'" />';
print $end8;
print '</p>';
}

//QUESTION NINE
if(!isset ($_POST['answer9'])){
print '<p> (9) '; 
print $start9;
print '<input class="white_back" type="text" name="answer9" size="10" value="'.$_POST['answer9'].'" />';
print $end9;
print '</p>';
}
elseif (empty($_POST['answer9'])){
print '<p>(9) ';
print $start9;
print '<input class= "yellow_back" type="text" name="answer9" size="10" value="'.$_POST['answer9'].'" />';
print $end9;
print '</p>';

}
elseif ($done==11){
if (($_POST['answer9'])==$correct9){
$_SESSION['answer9']="right";
$score++;
print '<p> (9) '; 
print $start9;
print '<input class = "green_back" type="text" name="answer9" size="10" value="'.$_POST['answer9'].'" />';
print $end9;
print '</p>';
}else{
$_SESSION['answer9']="wrong";
print '<p> (9) '; 
print $start9;
print '<input class = "red_back" type="text" name="answer9" size="10" value="'.$_POST['answer9'].'" />';
print $end9;
print '</p>';
}
}
else{
print '<p> (9) '; 
print $start9;
print '<input class="white_back" type="text" name="answer9" size="10" value="'.$_POST['answer9'].'" />';
print $end9;
print '</p>';
}

//QUESTION TEN
if(!isset ($_POST['answer10'])){
print '<p> (10) '; 
print $start10;
print '<input class="white_back" class="white_back" type="text" name="answer10" size="10" value="'.$_POST['answer10'].'" />';
print $end10;
print '</p>';
}
elseif (empty($_POST['answer10'])){
print '<p>(10) ';
print $start10;
print '<input class= "yellow_back" type="text" name="answer10" size="10" value="'.$_POST['answer10'].'" />';
print $end10;
print '</p>';

}
elseif ($done==11){
if (($_POST['answer10'])==$correct10){
$_SESSION['answer10']="right";
$score++;
print '<p> (10) '; 
print $start10;
print '<input class = "green_back" type="text" name="answer10" size="10" value="'.$_POST['answer10'].'" />';
print $end10;
print '</p>';
}else{
$_SESSION['answer10']="wrong";
print '<p> (10) '; 
print $start10;
print '<input class = "red_back" type="text" name="answer10" size="10" value="'.$_POST['answer10'].'" />';
print $end10;
print '</p>';
}
}
else{
print '<p> (10) '; 
print $start10;
print '<input class="white_back" type="text" name="answer10" size="10" value="'.$_POST['answer10'].'" />';
print $end10;
print '</p>';
}




print '</div>'; //exercise_box


print '<div id="button_box">';
if ($done !=11)
print '<p><input type="submit" name="submit" value="check answers"/></p>';
if (($done > 0)&&($done < 11))
print '<p class="incomplete_message">Answer all the questions before checking!</p>';
if($done==11){
if ($score==0)
$score="0";
print "<p class='score'>score: $score/10.<br/></p>";
print '<a href="tense_quiz_4.php"><p class="score">repeat quiz?</p></a>';
print '<a href="tense_quiz_4(KEY).php"><p class="score">study explanations?</p></a>';
print '</div>';
}
print '</div>'; //button_box

print '</form>';
print '</div>'; //content_box
print '</div>'; //wide_wrapper
?>
</body>
</html>

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.