Jump to content

Emergency!


Caitlin-havener

Recommended Posts

I have to turn this in for school. I had it working for the most part on my local Apache server, but now it is not working right on our school server. The guesses print down by the buttons was working, now it is not. When you guess a correct letter and it sets it to visible in the table, the correct letters dissappear when you guess another correct letter! And the whole guess_array is not printing out! Can you see any of the issues! It is at http://sulley.dm.ucf.edu/~ca081919/DIG3134/project2.php Code below:

<?php // woffer02.php	error_reporting(0);	session_start();	if (empty($_SESSION)) {    //Initialize session variables    $_SESSION['bad_guess_index'] = 0;    $_SESSION['guess_array'] = array();	$_SESSION['index']=0;	$_SESSION['turn']="GOLD"; //GOOD}?>		<!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">		<head>		<link rel="stylesheet" type="text/css" href="style_project_two.css" />		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />		<title></title>			<style type="text/css">			.mtable td 			{				width:50px;			}		</style>			</head>				<body>		<div id="wrap">		<div id="header"><h1>Caitlin's Jeopardy</h1></div>        <div id="right">		<form method="post">	<?php		#textloader:		function textloader($whatfile)		{				if (!file_exists($whatfile))		{			print "Sorry, can't find $whatfile.";			exit;		}		else		{			$textarray=file($whatfile);			return $textarray;			}		}# textloader	#display: Draws the Jeopardy table	function display($visible, $letters)	{		$letterlength=count($letters);		$letterlength-=1;		print "<table class='mtable' border=1><tr>";		for ($i=1; $i<$letterlength; $i++)		{						//print "i=$i,visible=".$visible[$i]."<br />";			if ($letters[$i]==' ')				print "</tr></table><br/>				<table class='mtable'><tr>";			else if ($visible[$i])			 {				print "<td><center>".$letters[$i]."</center></td>";			 }			else				print "<td> </td>";		}		print "</tr></table>";	}		#drawinputscreen: Asks for input.	function drawinputscreen($guesses)	{		print "<input type='text' name='guessletter'>";		print "Guess a letter. You have $guesses guesses left.";		print "<input type='submit' name='action' value='GUESS'>";		print "<input type='submit' name='action' value='REVEAL'>";		print "<input type='submit' name='action' value='NEXT PHRASE'>";		//print "<input type='submit' name='action' value='END SESSION'> (then refresh)";	}		######## MAIN PROGRAM ##########	//print"<img src='images/vanna.jpg' alt=''/>";		//initialize variables	$array= textloader("clichefile.txt");	$index=$_SESSION['index'];	$letters = array();	$act=isset($_POST['action']) ? $_POST['action'] : '';		$text = array_key_exists($index, $array) ? $array[$index] : "There are no more phrases left.";	$txtarr=($text);			//Print whos turn	$turn_print=$_SESSION['turn'];	print"<div id='team'>It is $turn_print team's turn.</div>";	//print "$text";			//Assign each letter to letters array and uppercase it		for ($i=0; $i<strlen($text);$i++)		{			$letters[$i+1]=strtoupper($text[$i]);			}				$letterlength=count($letters);		$visible=isset($_SESSION['visible']) ? $_SESSION['visible']: array();		$guesses=isset($_SESSION['guesses']) ? $_SESSION['guesses']: '';					/*	if(!$act){		for ($i=1; $i<=$letterlength; $i++)			$visible[$i]=0;					$guesses=16;	}	*/	switch ($act)	{			case '':			for ($i=1; $i<=$letterlength; $i++)			$visible[$i]=0;						//If there are no more phrases left		if ($text=="There are no more phrases left."){			for ($i=1; $i<=$letterlength; $i++)				$visible[$i]=1;		}					else{			for ($i=1; $i<=$letterlength; $i++)				$visible[$i]=0;		}			$guesses=16;		break;							case "GUESS":				$guessletter=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase					for ($i=1; $i<=$letterlength; $i++)			{				$ll=$letters[$i];				if ($guessletter==$letters[$i])				{					$visible[$i]=1;				}			}			//var_dump($_SESSION);								//WHOS TURN??			$turn=$_SESSION['turn'];			if ($turn=="GOLD"){				$_SESSION['turn']="BLACK";			}			else if($turn=="BLACK"){				$_SESSION['turn']="GOLD";			} #End whos turn												$guesses=$guesses-1;						//IF LETTER IS NOWHERE TO BE FOUND. 				$guess_index=isset($_SESSION['bad_guess_index']) ? $_SESSION['bad_guess_index']: '';							if (!(preg_match("/($guessletter)/",$text))){				print "<p class='right_side'>That letter was no where to be found.</p>";				$_SESSION['guess_array'][$guess_index] = $guessletter;				$_SESSION['bad_guess_index'] += 1;				$guess_index=isset($_SESSION['bad_guess_index']) ? $_SESSION['bad_guess_index']: '';				//print"$guess_index <br/>";			}		$bad_guess_print=isset($_SESSION['guess_array']) ? $_SESSION['guess_array']: array();					$guess_index=$_SESSION['bad_guess_index'];				print"<div id='bad_guesses'><p>Bad Guesses</p> <br />";		//print"$guess_index <br/>";			//foreach($guess_index as $value){			for($i=0; $i<$guess_index; $i++){				print"<p class='right_side' style='color:red'>$bad_guess_print[$i] </p>";			}		print"</div>";			break;			case "NEXT PHRASE":			$_SESSION['index']+= 1;		unset($_SESSION['bad_guess_index']);		unset($_SESSION['guess_array']);		unset($_SESSION['visible']);		unset($_SESSION['letters']);		unset($_SESSION['guesses']);		$guesses=16;		for ($i=1; $i<=$letterlength; $i++)				$visible[$i]=0;		break;				case "REVEAL":			for ($i=1; $i<=$letterlength; $i++)				$visible[$i]=1;			break;				case "END SESSION":			session_destroy();		break;	}					//RUN OUT OF GUESSES			if ($guesses==0){			print"<div id='lose'>You lose! Click NEXT PHRASE.</div>";		}		else if ($guesses==1){			print"<div id='last'>This is your last guess!!!</div>";		}			print"</div>";	print"<div id='left'>";	display($visible,$letters);		drawinputscreen($guesses);	print"</div>";			$_SESSION['visible']=$visible;	$_SESSION['guesses']=$guesses;		?><tt>Note: Guesses counter was working fine on local Apache server and the whole guess_array was printing as well. The correctly guessed letters were accumulating on the screen as they were guessed- as you see they are going away when another correct letter is guessed.They all are not working after being uploaded. Please let me know if you see the issues. Thanks. </tt></div></form></body></html>

Link to comment
Share on other sites

when you second time sending the data it losses the previous inputs cause your scripts does not know what letters are already revealed ...as its a field of a table not a input type so the data of the table you cant send back to the server to check (you can do that by ajax though) ...you have to detect it somehow.i think it will be best if you store each input in session say a , e,pthen manupulate the tables based on session (which has list of correct guess letter) and the latest input

Link to comment
Share on other sites

as i am not sure how you are aproaching it so it may be diffrent from your workflow...use something like...

$_SESSION['hangman'][]=$_POST['guessletter'];

$_POST['guessletter'] is the data which user gave in the form when he guesses something.so each time when user guess something it stores it in the session array. suppose user guesses 'a'..then 'e'..then 'o'so it would be assighned as $_SESSION['hangman'][1]='a'$_SESSION['hangman'][2]='e'$_SESSION['hangman'][3]='o'now check against the the manipulated text (eg. "eagle") that which inputs are coming in.everytime a user send a guess you check the inputs keystroke and the manipulated text.now as $_SESSION['hangman'][1],$_SESSION['hangman'][2] are matching the text so show them at your table and $_SESSION['hangman'][3] is not there so keep it hidden.step 1_a_ _ _step 2ea_ _estep 3 it did not change it cause last input "o" did not match the stringea_ _e

Link to comment
Share on other sites

Kay, I have the following for the part that saves the inputted letter into an array. It also is supposed to print the bad letters.

case "GUESS":			$bad_guess_index=isset($_SESSION['bad_guess_index']) ? $_SESSION['bad_guess_index']: '';		$all_guess_index= $_SESSION['all_guess_index'];				$_SESSION['guessletter'][$all_guess_index]=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase				for ($j=0; $j<=$all_guess_index; $j++){			for ($i=1; $i<=$letterlength; $i++)			{				$ll=$letters[$i];				if ($_SESSION['guessletter'][$j]==$letters[$i])				{					$visible[$i]=1;				}			}		}				for ($j=0; $j<=$all_guess_index; $j++){		$guessletter= $_SESSION['guessletter'];			if (!(preg_match("/$guessletter[$j]/i",$text))){					$_SESSION['guess_array'][$bad_guess_index] = $_SESSION['guessletter'][$j];				}		}						$_SESSION['all_guess_index'] += 1;			$_SESSION['bad_guess_index'] += 1;	

Unfortunately, again it is working on my local server but not when I put it onto our school server. I'm thinking the printing of everything including the table needs to be under each case maybe? So that it prints on each screen?? Or what, what next?Whole thing:

<?php // woffer02.php	error_reporting(0);	session_start();	if (empty($_SESSION)) {    //Initialize session variables    $_SESSION['bad_guess_index'] = 0;	$_SESSION['all_guess_index'] = 0;    $_SESSION['guess_array'] = array();	$_SESSION['index']=0;	$_SESSION['turn']="GOLD"; //GOOD}?>		<!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">		<head>		<link rel="stylesheet" type="text/css" href="style_project_two.css" />		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />		<title></title>			<style type="text/css">			.mtable td 			{				width:50px;			}		</style>			</head>				<body>		<div id="wrap">		<div id="header"><h1>Caitlin's Jeopardy</h1></div>        <div id="right">		<form method="post">	<?php		#textloader:		function textloader($whatfile)		{				if (!file_exists($whatfile))		{			print "Sorry, can't find $whatfile.";			exit;		}		else		{			$textarray=file($whatfile);			return $textarray;			}		}# textloader	#display: Draws the Jeopardy table	function display($visible, $letters)	{		$letterlength=count($letters);		print "<table class='mtable' border=1><tr>";		for ($i=1; $i<$letterlength; $i++)		{						//print "i=$i,visible=".$visible[$i]."<br />";			if ($letters[$i]==' ')				print "</tr></table><br/>				<table class='mtable'><tr>";			else if ($visible[$i])			 {				print "<td><center>".$letters[$i]."</center></td>";			 }			else				print "<td> </td>";		}		print "</tr></table>";	}		#drawinputscreen: Asks for input.	function drawinputscreen($guesses)	{		print "<input type='text' name='guessletter'>";		print "Guess a letter. You have $guesses guesses left.";		print "<input type='submit' name='action' value='GUESS'>";		print "<input type='submit' name='action' value='REVEAL'>";		print "<input type='submit' name='action' value='NEXT PHRASE'>";		//print "<input type='submit' name='action' value='END SESSION'> (then refresh)";	}		######## MAIN PROGRAM ##########	print"<img src='images/vanna.jpg' alt=''/>";		//initialize variables	$array= textloader("clichefile.txt");	$index=$_SESSION['index'];	//$letters = array();	$act=isset($_POST['action']) ? $_POST['action'] : '';		$text = array_key_exists($index, $array) ? $array[$index] : "There are no more phrases left.";	$txtarr=($text);			//Print whos turn	$turn_print=$_SESSION['turn'];	print"<div id='team'>It is $turn_print team's turn.</div>";	//print "$text";			//Assign each letter to letters array and uppercase it		for ($i=0; $i<strlen($text);$i++)		{			$letters[$i+1]=strtoupper($text[$i]);			}				$letterlength=count($letters);		$visible=$_SESSION['visible'];	$guesses=$_SESSION['guesses'];					/*	if(!$act){		for ($i=1; $i<=$letterlength; $i++)			$visible[$i]=0;					$guesses=16;	}	*/	switch ($act)	{			case '':			for ($i=1; $i<=$letterlength; $i++)			$visible[$i]=0;						//If there are no more phrases left		if ($text=="There are no more phrases left."){			for ($i=1; $i<=$letterlength; $i++)				$visible[$i]=1;		}					else{			for ($i=1; $i<=$letterlength; $i++)				$visible[$i]=0;		}			$guesses=16;		break;							case "GUESS":			$bad_guess_index=isset($_SESSION['bad_guess_index']) ? $_SESSION['bad_guess_index']: '';		$all_guess_index= $_SESSION['all_guess_index'];				$_SESSION['guessletter'][$all_guess_index]=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase				for ($j=0; $j<=$all_guess_index; $j++){			for ($i=1; $i<=$letterlength; $i++)			{				$ll=$letters[$i];				if ($_SESSION['guessletter'][$j]==$letters[$i])				{					$visible[$i]=1;				}			}		}				for ($j=0; $j<=$all_guess_index; $j++){		$guessletter= $_SESSION['guessletter'];			if (!(preg_match("/$guessletter[$j]/i",$text))){					$_SESSION['guess_array'][$bad_guess_index] = $_SESSION['guessletter'][$j];				}		}						$_SESSION['all_guess_index'] += 1;			$_SESSION['bad_guess_index'] += 1;														//WHOS TURN??			$turn=$_SESSION['turn'];			if ($turn=="GOLD"){				$_SESSION['turn']="BLACK";			}			else if($turn=="BLACK"){				$_SESSION['turn']="GOLD";			} #End whos turn												$guesses=$guesses-1;									break;							case "REVEAL":			for ($i=1; $i<=$letterlength; $i++)				$visible[$i]=1;			break;				case "END SESSION":			session_destroy();		break;			}						//RUN OUT OF GUESSES			if ($guesses==0){			print"<div id='lose'>You lose! Click NEXT PHRASE.</div>";		}		else if ($guesses==1){			print"<div id='last'>This is your last guess!!!</div>";		}			print"</div>";	print"<div id='left'>";	display($visible,$letters);		drawinputscreen($guesses);	print"</div>";			//print out the bad guesses	$bad_guess_print=isset($_SESSION['guess_array']) ? $_SESSION['guess_array']: array();				print"<div id='bad_guesses'><p>Bad Guesses</p> <br />";					for($i=0; $i<=$bad_guess_index; $i++){				print"<p class='right_side' style='color:red'>$bad_guess_print[$i] </p>";			}		print"</div>";		$_SESSION['visible']=$visible;	$_SESSION['guesses']=$guesses;		if ($act=="NEXT PHRASE"){			unset($_SESSION['bad_guess_index']);		unset($_SESSION['all_guess_index']);		unset($_SESSION['guessletter']);		unset($_SESSION['guess_array']);		unset($_SESSION['visible']);		unset($_SESSION['letters']);		unset($_SESSION['guesses']);		$_SESSION['index']+= 1;		$guesses=16;		for ($i=1; $i<=$letterlength; $i++)				$visible[$i]=0;			}	?></div></form></body></html>

Link to comment
Share on other sites

Made them all session variables. Still not working.

case "GUESS":			$bad_guess_index=isset($_SESSION['bad_guess_index']) ? $_SESSION['bad_guess_index']: '';		$all_guess_index= $_SESSION['all_guess_index'];				$_SESSION['guessletter'][$all_guess_index]=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase				for ($j=0; $j<=$all_guess_index; $j++){			for ($i=1; $i<=$letterlength; $i++)			{				$ll=$_SESSION['letters'][$i];				if ($_SESSION['guessletter'][$j]==$_SESSION['letters'][$i])				{					$_SESSION['visible'][$i]=1;				}			}		}				for ($j=0; $j<=$all_guess_index; $j++){		$guessletter= $_SESSION['guessletter'];			if (!(preg_match("/$guessletter[$j]/i",$text))){					$_SESSION['guess_array'][$bad_guess_index] = $_SESSION['guessletter'][$j];				}		}						$_SESSION['all_guess_index'] += 1;			$_SESSION['bad_guess_index'] += 1;	

Link to comment
Share on other sites

Whole thing now

<?php // woffer02.php	error_reporting(0);	session_start();	if (empty($_SESSION)) {    //Initialize session variables    $_SESSION['bad_guess_index'] = 0;	$_SESSION['all_guess_index'] = 0;    $_SESSION['guess_array'] = array();	$_SESSION['index']=0;	$_SESSION['turn']="GOLD"; //GOOD}?>		<!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">		<head>		<link rel="stylesheet" type="text/css" href="style_project_two.css" />		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />		<title></title>			<style type="text/css">			.mtable td 			{				width:50px;			}		</style>			</head>				<body>		<div id="wrap">		<div id="header"><h1>Caitlin's Jeopardy</h1></div>        <div id="right">		<form method="post">	<?php		#textloader:		function textloader($whatfile)		{				if (!file_exists($whatfile))		{			print "Sorry, can't find $whatfile.";			exit;		}		else		{			$textarray=file($whatfile);			return $textarray;			}		}# textloader	#display: Draws the Jeopardy table	function display($visible, $letters)	{		$letterlength=count($letters);		print "<table class='mtable' border=1><tr>";		for ($i=1; $i<$letterlength; $i++)		{						//print "i=$i,visible=".$visible[$i]."<br />";			if ($letters[$i]==' ')				print "</tr></table><br/>				<table class='mtable'><tr>";			else if ($visible[$i])			 {				print "<td><center>".$letters[$i]."</center></td>";			 }			else				print "<td> </td>";		}		print "</tr></table>";	}		#drawinputscreen: Asks for input.	function drawinputscreen($guesses)	{		print "<input type='text' name='guessletter'>";		print "Guess a letter. You have $guesses guesses left.";		print "<input type='submit' name='action' value='GUESS'>";		print "<input type='submit' name='action' value='REVEAL'>";		print "<input type='submit' name='action' value='NEXT PHRASE'>";		//print "<input type='submit' name='action' value='END SESSION'> (then refresh)";	}		######## MAIN PROGRAM ##########	print"<img src='images/vanna.jpg' alt=''/>";		//initialize variables	$array= textloader("clichefile.txt");	$index=$_SESSION['index'];	//$letters = array();	$act=isset($_POST['action']) ? $_POST['action'] : '';		$text = array_key_exists($index, $array) ? $array[$index] : "There are no more phrases left.";	$txtarr=($text);			//Print whos turn	$turn_print=$_SESSION['turn'];	print"<div id='team'>It is $turn_print team's turn.</div>";	//print "$text";			//Assign each letter to letters array and uppercase it		for ($i=0; $i<strlen($text);$i++)		{			$_SESSION['letters'][$i+1]=strtoupper($text[$i]);			}				$_SESSION['letterlength']=count($_SESSION['letters']);								switch ($act)	{			case '':			for ($i=1; $i<=$_SESSION['letterlength']; $i++)			$_SESSION['visible'][$i]=0;						//If there are no more phrases left		if ($text=="There are no more phrases left."){			for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=1;		}					else{			for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=0;		}			$_SESSION['guesses']=16;		break;							case "GUESS":			$bad_guess_index=isset($_SESSION['bad_guess_index']) ? $_SESSION['bad_guess_index']: '';		$all_guess_index= $_SESSION['all_guess_index'];				$_SESSION['guessletter'][$all_guess_index]=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase				for ($j=0; $j<=$all_guess_index; $j++){			for ($i=1; $i<=$_SESSION['letterlength']; $i++)			{				$ll=$_SESSION['letters'][$i];				if ($_SESSION['guessletter'][$j]==$_SESSION['letters'][$i])				{					$_SESSION['visible'][$i]=1;				}			}		}				for ($j=0; $j<=$all_guess_index; $j++){		$guessletter= $_SESSION['guessletter'];			if (!(preg_match("/$guessletter[$j]/i",$text))){					$_SESSION['guess_array'][$bad_guess_index] = $_SESSION['guessletter'][$j];				}		}						$_SESSION['all_guess_index'] += 1;			$_SESSION['bad_guess_index'] += 1;														//WHOS TURN??			$turn=$_SESSION['turn'];			if ($turn=="GOLD"){				$_SESSION['turn']="BLACK";			}			else if($turn=="BLACK"){				$_SESSION['turn']="GOLD";			} #End whos turn												$_SESSION['guesses']-= 1;	break;		case "NEXT PHRASE":		unset($_SESSION['bad_guess_index']);		unset($_SESSION['all_guess_index']);		unset($_SESSION['guessletter']);		unset($_SESSION['guess_array']);		unset($_SESSION['visible']);		unset($_SESSION['letters']);		unset($_SESSION['guesses']);		$_SESSION['index']+= 1;		$_SESSION['guesses']=16;		for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=0;		break;					case "REVEAL":			for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=1;			break;				case "END SESSION":			session_destroy();		break;			}						//RUN OUT OF GUESSES			if ($_SESSION['guesses']==0){			print"<div id='lose'>You lose! Click NEXT PHRASE.</div>";		}		else if ($_SESSION['guesses']==1){			print"<div id='last'>This is your last guess!!!</div>";		}			print"</div>";	print"<div id='left'>";		$letters=$_SESSION['letters'];	$visible=$_SESSION['visible'];	$guesses=$_SESSION['guesses'];	display($visible,$letters);		drawinputscreen($guesses);	print"</div>";			//print out the bad guesses	$bad_guess_print=isset($_SESSION['guess_array']) ? $_SESSION['guess_array']: array();				print"<div id='bad_guesses'><p>Bad Guesses</p> <br />";					for($i=0; $i<=$bad_guess_index; $i++){				print"<p class='right_side' style='color:red'>$bad_guess_print[$i] </p>";			}		print"</div>";		$_SESSION['visible']=$visible;	$_SESSION['guesses']=$guesses;	$_SESSION['letters']=$letters;		?></div></form></body></html>

Link to comment
Share on other sites

there is too many loops. you realy need those? i think its complexing the all..i think its can be done by more simpler manner

case 'GUESS':	  if(preg_match("/[$whatihavetoguess]/i",$_POST['guess']) //it will pick up the letter if it matches any letter	  $_SESSION['hangman'][]=$_POST['guess'];	  		// now do some var_dump  in $_SESSION['hangman'] to check input keystroke is correctly coming or not	   //if it is working then you can easily format the table herebreak;

Link to comment
Share on other sites

$_SESSION['hangman'][]=$_POST['guess'];this line will do that for you. the"[]" ( bold marked) will tell php to store $_POST['guess'] in next index(numerical) of $_SESSION['hangman']

Link to comment
Share on other sites

That helped me eliminate a loop but I need the other one because it is checking each letter individually as an array and if it is in the text it is setting it as visible (or '1'). If it is not visible it will remain a value of '0'. Every time I type in a new letter and hit guess- my visible array is resetting. The cells that had a value of '1' are going back to '0'. Do you see that?

$_SESSION['guessletter'][]=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase					for ($i=1; $i<=$_SESSION['letterlength']; $i++)			{				$ll=$_SESSION['letters'][$i];				if ($_SESSION['guessletter']==$_SESSION['letters'][$i])				{					$_SESSION['visible'][$i]=1;				}			}

Anyone that could help would be VERY appreciated! I'm late on this and I'm literally pulling my hair out, and getting too tired to think lol.Whole thing:

<?php // woffer02.php	error_reporting(0);	session_start();	if (empty($_SESSION)) {    //Initialize session variables    $_SESSION['bad_guess_index'] = 0;	$_SESSION['all_guess_index'] = 0;    $_SESSION['guess_array'] = array();	$_SESSION['index']=0;	$_SESSION['turn']="GOLD"; //GOOD}?>		<!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">		<head>		<link rel="stylesheet" type="text/css" href="style_project_two.css" />		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />		<title></title>			<style type="text/css">			.mtable td 			{				width:50px;			}		</style>			</head>				<body>		<div id="wrap">		<div id="header"><h1>Caitlin's Jeopardy</h1></div>        <div id="right">		<form method="post">	<?php		#textloader:		function textloader($whatfile)		{				if (!file_exists($whatfile))		{			print "Sorry, can't find $whatfile.";			exit;		}		else		{			$textarray=file($whatfile);			return $textarray;			}		}# textloader	#display: Draws the Jeopardy table	function display($visible, $letters)	{		$letterlength=count($letters);		print "<table class='mtable' border=1><tr>";		for ($i=1; $i<$letterlength; $i++)		{						print "i=$i,visible=".$visible[$i]."<br />";			if ($letters[$i]==' ')				print "</tr></table><br/>				<table class='mtable'><tr>";			else if ($visible[$i])			 {				print "<td><center>".$letters[$i]."</center></td>";			 }			else				print "<td> </td>";		}		print "</tr></table>";	}		#drawinputscreen: Asks for input.	function drawinputscreen($guesses)	{		print "<input type='text' name='guessletter'>";		print "Guess a letter. You have $guesses guesses left.";		print "<input type='submit' name='action' value='GUESS'>";		print "<input type='submit' name='action' value='REVEAL'>";		print "<input type='submit' name='action' value='NEXT PHRASE'>";		//print "<input type='submit' name='action' value='END SESSION'> (then refresh)";	}		######## MAIN PROGRAM ##########	print"<img src='images/vanna.jpg' alt=''/>";		//initialize variables	$array= textloader("clichefile.txt");	$index=$_SESSION['index'];	//$letters = array();	$act=isset($_POST['action']) ? $_POST['action'] : '';		$text = array_key_exists($index, $array) ? $array[$index] : "There are no more phrases left.";	$txtarr=($text);			//Print whos turn	$turn_print=$_SESSION['turn'];	print"<div id='team'>It is $turn_print team's turn.</div>";	//print "$text";			//Assign each letter to letters array and uppercase it		for ($i=0; $i<strlen($text);$i++)		{			$_SESSION['letters'][$i+1]=strtoupper($text[$i]);			}				$_SESSION['letterlength']=count($_SESSION['letters']);				;				switch ($act)	{			case '':									//If there are no more phrases left		if ($text=="There are no more phrases left."){			for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=1;		}					else{			for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=0;		}		$_SESSION['guesses']=16;		break;							case "GUESS":				 /*if(preg_match("/$text/i",$_POST['guessletter'])){ //it will pick up the letter if it matches any letter      		$_SESSION['guessletter'][]=$_POST['guessletter'];	  		$print=$_SESSION['guessletter'];	  		print "$print";}*/	  		$_SESSION['guessletter'][]=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase					for ($i=1; $i<=$_SESSION['letterlength']; $i++)			{				$ll=$_SESSION['letters'][$i];				if ($_SESSION['guessletter']==$_SESSION['letters'][$i])				{					$_SESSION['visible'][$i]=1;				}			}				var_dump($_SESSION);				$guessletter= $_SESSION['guessletter'];			if (!(preg_match("/$guessletter/i",$text))){					$_SESSION['guess_array'][] = $_SESSION['guessletter'];				}									//WHOS TURN??			$turn=$_SESSION['turn'];			if ($turn=="GOLD"){				$_SESSION['turn']="BLACK";			}			else if($turn=="BLACK"){				$_SESSION['turn']="GOLD";			} #End whos turn												$_SESSION['guesses']-= 1;	break;		case "NEXT PHRASE":		unset($_SESSION['bad_guess_index']);		unset($_SESSION['all_guess_index']);		unset($_SESSION['guessletter']);		unset($_SESSION['guess_array']);		unset($_SESSION['visible']);		unset($_SESSION['letters']);		unset($_SESSION['guesses']);		$_SESSION['index']+= 1;		$_SESSION['guesses']=16;		for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=0;		break;					case "REVEAL":			for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=1;			break;				case "END SESSION":			session_destroy();		break;			}						//RUN OUT OF GUESSES			if ($_SESSION['guesses']==0){			print"<div id='lose'>You lose! Click NEXT PHRASE.</div>";		}		else if ($_SESSION['guesses']==1){			print"<div id='last'>This is your last guess!!!</div>";		}			print"</div>";	print"<div id='left'>";		$letters=$_SESSION['letters'];	$visible=$_SESSION['visible'];	$guesses=$_SESSION['guesses'];	display($visible,$letters);		drawinputscreen($guesses);	print"</div>";			//print out the bad guesses	$bad_guess_print=isset($_SESSION['guess_array']) ? $_SESSION['guess_array']: array();				print"<div id='bad_guesses'><p>Bad Guesses</p> <br />";					for($i=0; $i<=$bad_guess_index; $i++){				print"<p class='right_side' style='color:red'>$bad_guess_print[$i] </p>";			}		print"</div>";		$_SESSION['visible']=$visible;	$_SESSION['guesses']=$guesses;	$_SESSION['letters']=$letters;		?></div></form></body></html>

Link to comment
Share on other sites

$_SESSION['guessletter'][]=strtoupper($_POST['guessletter']); // a-> A, etc. uppercasefor ($i=1; $i<=$_SESSION['letterlength']; $i++){$ll=$_SESSION['letters'][$i];if ($_SESSION['guessletter']==$_SESSION['letters'][$i]){$_SESSION['visible'][$i]=1;}}
if ($_SESSION['guessletter']==$_SESSION['letters'][$i])
$_SESSION['guessletter'] is array so it is not actually checking the element of it. you need to loop through the $_SESSION['guessletter'] array to check each element.mean something like...
for ($i=0; $i<=$_SESSION['letterlength']; $i++){for($j=0;$j<=count($_SESSION['guessletter']);$j++) {	if ($_SESSION['guessletter'][$j]==$_SESSION['letters'][$i])	//do something }}

array index starts with 0

Link to comment
Share on other sites

i think instead of looping preg_replace will work good here. i think it will be more simple and clean (did not tested but should work)

$whitelist=implode("",$_SESSION['guessletter'])echo preg_replace("/[^$whitelist]/i","*",$guessword);//it will mask the unrevealed letter with star and will display result which guessed correct..and will output it up. it will do the same job eliminating the loops

whole code:

case 'GUESS':	  if(preg_match("/[$guessword]/i",$_POST['guess']) //it will pick up the letter if it matches any letter	  $_SESSION['guessletter'][]=$_POST['guess'];	  $whitelist=implode("",$_SESSION['guessletter'])	 echo preg_replace("/[^$whitelist]/i","*",$guessword);	 	   //it will mask the unrevealed letter with star and will display result which guessed correct..and will output it up. it  will do the same job eliminating the loopsbreak;

Link to comment
Share on other sites

i think if it's working locally but not working on the live server, I would check the PHP versions. Perhaps something you are using is from a newer version of PHP than the one you're deploying too. A simple test is to make a php file with this in it:phpinfo.php

<?phpphpinfo();?>

open that page locally and on your schools server, and compare the information returned, in particular the version number of PHP being supported.

Link to comment
Share on other sites

I've tried your way and it does the same thing. "guess" is hit and it displays where all that correct guessletter shows up. It is hit again and it erases the previous work and does the next letter.Example:phrase "an apple a day keeps the doctor away";guessletter="A""GUESS" is pushed.prints a* a**** a *a* ***** *** ****** a*a*guessletter="P""GUESS" is pushed.prints ** *pp** * *** ***** *** ****** ****It needs to print this!!!! a* app** a *a* ***** *** ****** a*a*I've tried EVERYTHING! I'm even trying to store the $visible[$i] array inside this_guess array then looping through each visible array inside of this_guess array to get it to work. It's rediculous! And mind boggling!! ANYONE please!!! Most of my attempts have worked on local server but not on school server and I just can't get it!My latest attempt making array inside of array:

$_SESSION['guessletter']=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase					for ($i=1; $i<=$_SESSION['letterlength']; $i++)			{					if ($_SESSION['guessletter']==$_SESSION['letters'][$i])					{						$visible[$i]=1;						$_SESSION['this_guess'][]=$visible;					}				}

Later it calls a function to print it out:

#display: Draws the Jeopardy table	function display($visible, $letters)	{		$letterlength=count($letters);		print "<table class='mtable' border=1><tr>";		for ($i=1; $i<$letterlength; $i++)		{			for ($j=0; $j<=count($_SESSION['this_guess']); $j++){				print "i=$i,visible=".$visible[$i]."<br />";				if ($letters[$i]==' ')					print "</tr></table><br/>					<table class='mtable'><tr>";				else if ($_SESSION['this_guess'][$j])			 	{					if($visible[$i])					print "<td><center>".$letters[$i]."</center></td>";			 	}				else					print "<td> </td>";										   }		}		print "</tr></table>";	}

Link to comment
Share on other sites

I've tried your way and it does the same thing. "guess" is hit and it displays where all that correct guessletter shows up. It is hit again and it erases the previous work and does the next letter.Example:phrase "an apple a day keeps the doctor away";guessletter="A""GUESS" is pushed.prints a* a**** a *a* ***** *** ****** a*a*guessletter="P""GUESS" is pushed.prints ** *pp** * *** ***** *** ****** ****It needs to print this!!!! a* app** a *a* ***** *** ****** a*a*I've tried EVERYTHING! I'm even trying to store the $visible[$i] array inside this_guess array then looping through each visible array inside of this_guess array to get it to work. It's rediculous! And mind boggling!! ANYONE please!!! Most of my attempts have worked on local server but not on school server and I just can't get it!My latest attempt making array inside of array:

$_SESSION['guessletter']=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase					for ($i=1; $i<=$_SESSION['letterlength']; $i++)			{					if ($_SESSION['guessletter']==$_SESSION['letters'][$i])					{						$visible[$i]=1;						$_SESSION['this_guess'][]=$visible;					}				}

Later it calls a function to print it out:

#display: Draws the Jeopardy table	function display($visible, $letters)	{$letters=$_SESSION['letters'];	$visible=$_SESSION['visible'];	$guesses=$_SESSION['guesses'];		$letterlength=count($letters);		print "<table class='mtable' border=1><tr>";		for ($i=1; $i<$letterlength; $i++)		{			for ($j=0; $j<=count($_SESSION['this_guess']); $j++){				print "i=$i,visible=".$visible[$i]."<br />";				if ($letters[$i]==' ')					print "</tr></table><br/>					<table class='mtable'><tr>";				else if ($_SESSION['this_guess'][$j])			 	{					if($visible[$i])					print "<td><center>".$letters[$i]."</center></td>";			 	}				else					print "<td> </td>";										   }		}		print "</tr></table>";	}

Whole thing:

<?php // woffer02.php	error_reporting(0);	session_start();	if (empty($_SESSION)) {    //Initialize session variables    $_SESSION['bad_guess_index'] = 0;	$_SESSION['all_guess_index'] = 0;    $_SESSION['guess_array'] = array();	$_SESSION['index']=0;	$_SESSION['turn']="GOLD"; //GOOD}?>		<!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">		<head>		<link rel="stylesheet" type="text/css" href="style_project_two.css" />		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />		<title></title>			<style type="text/css">			.mtable td 			{				width:50px;			}		</style>			</head>				<body>		<div id="wrap">		<div id="header"><h1>Caitlin's Jeopardy</h1></div>        <div id="right">		<form method="post">	<?php		#textloader:		function textloader($whatfile)		{				if (!file_exists($whatfile))		{			print "Sorry, can't find $whatfile.";			exit;		}		else		{			$textarray=file($whatfile);			return $textarray;			}		}# textloader	#display: Draws the Jeopardy table	function display($visible, $letters)	{		$letterlength=count($letters);		print "<table class='mtable' border=1><tr>";		for ($i=1; $i<$letterlength; $i++)		{			for ($j=0; $j<=count($_SESSION['this_guess']); $j++){				print "i=$i,visible=".$visible[$i]."<br />";				if ($letters[$i]==' ')					print "</tr></table><br/>					<table class='mtable'><tr>";				else if ($_SESSION['this_guess'][$j])			 	{					if($visible[$i])					print "<td><center>".$letters[$i]."</center></td>";			 	}				else					print "<td> </td>";										   }		}		print "</tr></table>";	}		#drawinputscreen: Asks for input.	function drawinputscreen($guesses)	{		print "<input type='text' name='guessletter'>";		print "Guess a letter. You have $guesses guesses left.";		print "<input type='submit' name='action' value='GUESS'>";		print "<input type='submit' name='action' value='REVEAL'>";		print "<input type='submit' name='action' value='NEXT PHRASE'>";		//print "<input type='submit' name='action' value='END SESSION'> (then refresh)";	}		######## MAIN PROGRAM ##########	print"<img src='images/vanna.jpg' alt=''/>";		//initialize variables	$array= textloader("clichefile.txt");	$index=$_SESSION['index'];	//$letters = array();	$act=isset($_POST['action']) ? $_POST['action'] : '';		$text = array_key_exists($index, $array) ? $array[$index] : "There are no more phrases left.";	$txtarr=($text);			//Print whos turn	$turn_print=$_SESSION['turn'];	print"<div id='team'>It is $turn_print team's turn.</div>";	//print "$text";			//Assign each letter to letters array and uppercase it		for ($i=0; $i<strlen($text);$i++)		{			$_SESSION['letters'][$i+1]=strtoupper($text[$i]);			}				$_SESSION['letterlength']=count($_SESSION['letters']);				;				switch ($act)	{			case '':									//If there are no more phrases left		if ($text=="There are no more phrases left."){			for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=1;		}					else{			for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=0;		}		$_SESSION['guesses']=16;		break;							case "GUESS":/*		 if(preg_match("/[$text]/i",$_POST['guessletter'])){ //it will pick up the letter if it matches any letter      $_SESSION['guessletter'][]=$_POST['guessletter'];      $whitelist=implode("",$_SESSION['guessletter']);    $newtext= preg_replace("/[^$whitelist]/i","*",$text);	 print "h: $newtext";*/										          //it will mask the unrevealed letter with star and will display result which guessed correct..and will output it up. it  will do the same job eliminating the loops	  		$_SESSION['guessletter']=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase					for ($i=1; $i<=$_SESSION['letterlength']; $i++)			{					if ($_SESSION['guessletter']==$_SESSION['letters'][$i])					{						$visible[$i]=1;						$_SESSION['this_guess'][]=$visible;					}				}			$one=$_SESSION['this_guess'];			$two=$_SESSION['this_guess'][1];		print "This guess one: $two<br/>";		print "This guess two:";		print count($one);						$guessletter= $_SESSION['guessletter'];			if (!(preg_match("/$guessletter/i",$text))){					$_SESSION['guess_array'][] = $_SESSION['guessletter'];				}									//WHOS TURN??			$turn=$_SESSION['turn'];			if ($turn=="GOLD"){				$_SESSION['turn']="BLACK";			}			else if($turn=="BLACK"){				$_SESSION['turn']="GOLD";			} #End whos turn												$_SESSION['guesses']-= 1;	break;		case "NEXT PHRASE":		unset($_SESSION['bad_guess_index']);		unset($_SESSION['all_guess_index']);		unset($_SESSION['guessletter']);		unset($_SESSION['guess_array']);		unset($_SESSION['visible']);		unset($_SESSION['letters']);		unset($_SESSION['guesses']);		$_SESSION['index']+= 1;		$_SESSION['guesses']=16;		for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=0;		break;					case "REVEAL":			for ($i=1; $i<=$_SESSION['letterlength']; $i++)				$_SESSION['visible'][$i]=1;			break;				case "END SESSION":			session_destroy();		break;			}						//RUN OUT OF GUESSES			if ($_SESSION['guesses']==0){			print"<div id='lose'>You lose! Click NEXT PHRASE.</div>";		}		else if ($_SESSION['guesses']==1){			print"<div id='last'>This is your last guess!!!</div>";		}			print"</div>";	print"<div id='left'>";		$letters=$_SESSION['letters'];	$visible=$_SESSION['visible'];	$guesses=$_SESSION['guesses'];	var_dump($_SESSION);	display($visible,$letters);		drawinputscreen($guesses);	print"</div>";			//print out the bad guesses	$bad_guess_print=isset($_SESSION['guess_array']) ? $_SESSION['guess_array']: array();				print"<div id='bad_guesses'><p>Bad Guesses</p> <br />";					for($i=0; $i<=$bad_guess_index; $i++){				print"<p class='right_side' style='color:red'>$bad_guess_print[$i] </p>";			}		print"</div>";		$_SESSION['visible']=$visible;	$_SESSION['guesses']=$guesses;	$_SESSION['letters']=$letters;		?></div></form></body></html>

Sorry I know its getting messy :)

Link to comment
Share on other sites

i think if it's working locally but not working on the live server, I would check the PHP versions. Perhaps something you are using is from a newer version of PHP than the one you're deploying too. A simple test is to make a php file with this in it:phpinfo.php
<?phpphpinfo();?>

open that page locally and on your schools server, and compare the information returned, in particular the version number of PHP being supported.

Link to comment
Share on other sites

I've tried your way and it does the same thing. "guess" is hit and it displays where all that correct guessletter shows up. It is hit again and it erases the previous work and does the next letter.Example:phrase "an apple a day keeps the doctor away";guessletter="A""GUESS" is pushed.prints a* a**** a *a* ***** *** ****** a*a*guessletter="P""GUESS" is pushed.prints ** *pp** * *** ***** *** ****** ****It needs to print this!!!!a* app** a *a* ***** *** ****** a*a*I've tried EVERYTHING! I'm even trying to store the $visible[$i] array inside this_guess array then looping through each visible array inside of this_guess array to get it to work. It's rediculous! And mind boggling!!ANYONE please!!! Most of my attempts have worked on local server but not on school server and I just can't get it!My latest attempt making array inside of array:CODE$_SESSION['guessletter']=strtoupper($_POST['guessletter']); // a-> A, etc. uppercasefor ($i=1; $i<=$_SESSION['letterlength']; $i++){if ($_SESSION['guessletter']==$_SESSION['letters'][$i]){$visible[$i]=1;$_SESSION['this_guess'][]=$visible;}}Later it calls a function to print it out:CODE#display: Draws the Jeopardy tablefunction display($visible, $letters){$letters=$_SESSION['letters'];$visible=$_SESSION['visible'];$guesses=$_SESSION['guesses'];$letterlength=count($letters);print "<table class='mtable' border=1><tr>";for ($i=1; $i<$letterlength; $i++){for ($j=0; $j<=count($_SESSION['this_guess']); $j++){print "i=$i,visible=".$visible[$i]."<br />";if ($letters[$i]==' ')print "</tr></table><br/><table class='mtable'><tr>";else if ($_SESSION['this_guess'][$j]){if($visible[$i])print "<td><center>".$letters[$i]."</center></td>";}elseprint "<td> </td>";}}print "</tr></table>";}Whole thing:CODE<?php // woffer02.phperror_reporting(0);session_start();if (empty($_SESSION)) {//Initialize session variables$_SESSION['bad_guess_index'] = 0;$_SESSION['all_guess_index'] = 0;$_SESSION['guess_array'] = array();$_SESSION['index']=0;$_SESSION['turn']="GOLD"; //GOOD}?><!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"><head><link rel="stylesheet" type="text/css" href="style_project_two.css" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title></title><style type="text/css">.mtable td{width:50px;}</style></head><body><div id="wrap"><div id="header"><h1>Caitlin's Jeopardy</h1></div><div id="right"><form method="post"><?php#textloader:function textloader($whatfile){if (!file_exists($whatfile)){print "Sorry, can't find $whatfile.";exit;}else{$textarray=file($whatfile);return $textarray;}}# textloader#display: Draws the Jeopardy tablefunction display($visible, $letters){$letterlength=count($letters);print "<table class='mtable' border=1><tr>";for ($i=1; $i<$letterlength; $i++){for ($j=0; $j<=count($_SESSION['this_guess']); $j++){print "i=$i,visible=".$visible[$i]."<br />";if ($letters[$i]==' ')print "</tr></table><br/><table class='mtable'><tr>";else if ($_SESSION['this_guess'][$j]){if($visible[$i])print "<td><center>".$letters[$i]."</center></td>";}elseprint "<td> </td>";}}print "</tr></table>";}#drawinputscreen: Asks for input.function drawinputscreen($guesses){print "<input type='text' name='guessletter'>";print "Guess a letter. You have $guesses guesses left.";print "<input type='submit' name='action' value='GUESS'>";print "<input type='submit' name='action' value='REVEAL'>";print "<input type='submit' name='action' value='NEXT PHRASE'>";//print "<input type='submit' name='action' value='END SESSION'> (then refresh)";}######## MAIN PROGRAM ##########print"<img src='images/vanna.jpg' alt=''/>";//initialize variables$array= textloader("clichefile.txt");$index=$_SESSION['index'];//$letters = array();$act=isset($_POST['action']) ? $_POST['action'] : '';$text = array_key_exists($index, $array) ? $array[$index] : "There are no more phrases left.";$txtarr=($text);//Print whos turn$turn_print=$_SESSION['turn'];print"<div id='team'>It is $turn_print team's turn.</div>";//print "$text";//Assign each letter to letters array and uppercase itfor ($i=0; $i<strlen($text);$i++){$_SESSION['letters'][$i+1]=strtoupper($text[$i]);}$_SESSION['letterlength']=count($_SESSION['letters']);;switch ($act){case ''://If there are no more phrases leftif ($text=="There are no more phrases left."){for ($i=1; $i<=$_SESSION['letterlength']; $i++)$_SESSION['visible'][$i]=1;}else{for ($i=1; $i<=$_SESSION['letterlength']; $i++)$_SESSION['visible'][$i]=0;}$_SESSION['guesses']=16;break;case "GUESS":/*if(preg_match("/[$text]/i",$_POST['guessletter'])){ //it will pick up the letter if it matches any letter$_SESSION['guessletter'][]=$_POST['guessletter'];$whitelist=implode("",$_SESSION['guessletter']);$newtext= preg_replace("/[^$whitelist]/i","*",$text);print "h: $newtext";*///it will mask the unrevealed letter with star and will display result which guessed correct..and will output it up. it will do the same job eliminating the loops$_SESSION['guessletter']=strtoupper($_POST['guessletter']); // a-> A, etc. uppercasefor ($i=1; $i<=$_SESSION['letterlength']; $i++){if ($_SESSION['guessletter']==$_SESSION['letters'][$i]){$visible[$i]=1;$_SESSION['this_guess'][]=$visible;}}$one=$_SESSION['this_guess'];$two=$_SESSION['this_guess'][1];print "This guess one: $two<br/>";print "This guess two:";print count($one);$guessletter= $_SESSION['guessletter'];if (!(preg_match("/$guessletter/i",$text))){$_SESSION['guess_array'][] = $_SESSION['guessletter'];}//WHOS TURN??$turn=$_SESSION['turn'];if ($turn=="GOLD"){$_SESSION['turn']="BLACK";}else if($turn=="BLACK"){$_SESSION['turn']="GOLD";} #End whos turn$_SESSION['guesses']-= 1;break;case "NEXT PHRASE":unset($_SESSION['bad_guess_index']);unset($_SESSION['all_guess_index']);unset($_SESSION['guessletter']);unset($_SESSION['guess_array']);unset($_SESSION['visible']);unset($_SESSION['letters']);unset($_SESSION['guesses']);$_SESSION['index']+= 1;$_SESSION['guesses']=16;for ($i=1; $i<=$_SESSION['letterlength']; $i++)$_SESSION['visible'][$i]=0;break;case "REVEAL":for ($i=1; $i<=$_SESSION['letterlength']; $i++)$_SESSION['visible'][$i]=1;break;case "END SESSION":session_destroy();break;}//RUN OUT OF GUESSESif ($_SESSION['guesses']==0){print"<div id='lose'>You lose! Click NEXT PHRASE.</div>";}else if ($_SESSION['guesses']==1){print"<div id='last'>This is your last guess!!!</div>";}print"</div>";print"<div id='left'>";$letters=$_SESSION['letters'];$visible=$_SESSION['visible'];$guesses=$_SESSION['guesses'];var_dump($_SESSION);display($visible,$letters);drawinputscreen($guesses);print"</div>";//print out the bad guesses$bad_guess_print=isset($_SESSION['guess_array']) ? $_SESSION['guess_array']: array();print"<div id='bad_guesses'><p>Bad Guesses</p> <br />";for($i=0; $i<=$bad_guess_index; $i++){print"<p class='right_side' style='color:red'>$bad_guess_print[$i] </p>";}print"</div>";$_SESSION['visible']=$visible;$_SESSION['guesses']=$guesses;$_SESSION['letters']=$letters;?></div></form></body></html>Sorry I know its getting messy sad.gif
it should work ...i think you are doing same thing as you done before
$_SESSION['guessletter']=strtoupper($_POST['guessletter']);

should be

$_SESSION['guessletter'][]=strtoupper($_POST['guessletter']);

it is rewriting the guessed letter everytime unless you dont add []. it will assighn new inputs to new index.

for ($i=1; $i<=$_SESSION['letterlength']; $i++)
array index starts with 0. did you read the previouse post?
Link to comment
Share on other sites

I changed it back to what it was. working on local server only. Local server says "Apache/2.2.17 (Win32) PHP/5.3.4 " and school server says "Apache/2.2.14 (Ubuntu) " but can't find php version. Where would I find this? And how would I fix it anyway??

Link to comment
Share on other sites

You can find out the PHP version on the server by running the file thescientist talked about.As for how to fix the bug... it depends on what the server's version is. Knowing that will tell us which changelogs to look at which in turn will give us a clue as to why this happens. Most likely, it's a PHP bug that was fixed in recent versions of PHP (5.3.4) but was still present in earlier ones. To find out a workaround, we need to know the bug we're dealing with first.

Link to comment
Share on other sites

You can find out the PHP version on the server by running the file thescientist talked about.As for how to fix the bug... it depends on what the server's version is. Knowing that will tell us which changelogs to look at which in turn will give us a clue as to why this happens. Most likely, it's a PHP bug that was fixed in recent versions of PHP (5.3.4) but was still present in earlier ones. To find out a workaround, we need to know the bug we're dealing with first.
School server: PHP/5.3.2-1ubuntu4.5 Local server: PHP/5.3.4
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...