Jump to content

Parse Error Help Please


webdevdea

Recommended Posts

 This is what is happening..

Parse error: syntax error, unexpected $end in /Applications/XAMPP/xamppfiles/htdocs/Assignments php class/battleship/testing123.php on line 991

<?php session_start() ?>


 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">


<head>


<title>BATTLESHIP</title>


<link rel = "stylesheet"


      type = "text/css"


      href = "battleship.css" />


      


</head>


 


<body>


 


 


<?php


 


if(isset($_POST['start_game']))


{


	if (isset($_POST["counter"]))


	{


		$counter = $_POST["counter"];


	}


	else 


	{


		$counter = 0;


	} 


$counter++;


 


$_SESSION["counter"] = $counter;


 


if(isset($_POST['choice']))


{


	if($_POST['choice']=="correct")


	print "<br>You got it!


	It took you $counter tries. <br>";


}


 


$myGuess=rand($lowest,$highest);


 


$form = "showOptions";


 


 


 


$form = "showStart";


 


 


if($form == "showOptions")


 


?>


<h4>


<form method="post" action="" name="target">


<input type="Submit" value="Submit" align="MIDDLE">


</form></h4>


 


<?php


$step = $_POST['step']; 


 


if ($step > 2) 


{


	$step = 0; 


}


else


{


	$step += 1; 


}


 


if ($step == 0) 


{ 


	for ($i = a; $i < k; $i++)


	{


		echo "<tr><td width='10' align ='right'>$i</td>"; 


        for ($j = 1; $j < 11; $j++)


		{ 


			echo "<td><input type='submit' value='fire' name='$i$j'></td>"; 


		} 


			echo "</tr>"; 


	}


		echo "<tr><td></td>"; 


	for ($j = 1; $j < 11; $j++)


	{ 


		echo "<td>$j</td>"; 


	} 


		echo "</tr></table>"; 


	if ($step == 1) 


	{ 


		for ($i = a; $i < k; $i++)


		{


			echo "<tr><td width='10' align='right'>$i</td>";


		}


		for ($j = 1; $j < 11; $j++)


		{ 


		    echo "<td><input type='submit' value='fire' name='$i$j'></td>"; 


		} 


			echo "</tr>"; 


	}


    echo "<tr><td></td>"; 


    for ($j = 1; $j < 11; $j++)


	{


		echo "<td>$j</td>"; 


	} 


	{


		echo "</tr></table>"; 


	}


	{ 


		echo "Result  ";


	}


	for ($i = a; $i < k; $i++)


	{


		echo "<tr><td width='10' align='right'>$i</td>"; 


	}


	for ($j = 1; $j < 11; $j++)


	{ 


		echo "<td> <input type='checkbox' checked='checked' disabled='disabled' name='$i$j'></td>"; 


	}


		echo "</tr>"; 


	


		echo "<tr><td></td>"; 


	for ($j = 1; $j < 11; $j++)


	{ 


		echo "<td>$j</td>"; 


	} 


	    echo "</tr></table><br><input type='submit' name='' value='shoot'>"; 


}	


 


?>


 


 


 


 


<?php


 


echo '<table width="300" height="300" border="1" align="center">';


 


 


for ( $row = 1; $row <= 10; $row++ )


{	


	echo '<tr>';


	


	for( $col = 1; $col <= 10; $col++ ) 


	{


		echo '<td width="30" align="center">';


		echo ( isset($grid[$row][$col]) ? $grid[$row][$col] : ' ' );


		echo '</td>';


	}


		echo '</tr>';


} 


		echo '</table>';


 


 


?>


<input type="hidden" name="step" value="<?php echo "$step";?>" />


 


 


 


 


 


<?php


$ships = array 


(


	'carrier' => 5,


	'battleship' => 4,


	'cruiser' => 3,


	'submarine' => 3,


	'destroyer' => 2


);


 


$grid = array();


 


foreach($ships as $name => $size)


{


while (TRUE) 


{


	$axis = (mt_rand(0,1) == 1 ? 'x' : 'y' );


	$max = array( 'x' => 10, 'y' => 10 );


	$max[$axis] -= $size;


	$x = mt_rand(1, $max['x'] );


	$y = mt_rand(1, $max['y'] );


	


	for ($i = 0; $i < $size; $i++)


	{


		$curr = array ( 'x' => $x, 'y' => $y );


		$curr[$axis] += $i;


		if (isset($grid[$curr['x']][$curr['y']]))


		continue 2;


	}	


break;


}


 


for ( $i = 0; $i < $size; $i++)


{


	$curr = array ( 'x' =>  $x, 'y' => $y );


	$curr[$axis] += $i;


	$grid[$curr['x']][$curr['y']]=substr($name, 0, 1);


}


}


 


 


$r = array_rand($row);


$c = rand(1,10)-1;


$randBoard = $row[$r][$c];


print "<p>$randBoard</p>";


 


function createBoard()


{


$column1 = array(


'a1','a2','a3','a4','a5','a6','a7','a8','a9','a10'


);


$column2 = array(


'b1','b2','b3','b4','b5','b6','b7','b8','b9','b10'


);


$column3 = array(


'c1','c2','c3','c4','c5','c6','c7','c8','c9','c10'


);


$column4 = array(


'd1','d2','d3','d4','d5','d6','d7','d8','d9','d10'


);


$column5 = array(


'e1','e2','e3','e4','e5','e6','e7','e8','e9','e10'


);


$column6 = array(


'f1','f2','f3','f4','f5','f6','f7','f8','f9','f10'


);


$column7 = array(


'g1','g2','g3','g4','g5','g6','g7','g8','g9','g10'


);


$column8 = array(


'h1','h2','h3','h4','h5','h6','h7','h8','h9','h10'


);


$column9 = array(


'i1','i2','i3','i4','i5','i6','i7','i8','i9','i10'


);


$column10 = array(


'j1','j2','j3','j4','j5','j6','j7','j8','j9','j10'


);


}


 


$row = array(


"a"=>$column1,


"b"=>$column2,


"c"=>$column3,


"d"=>$column4,


"e"=>$column5,


"f"=>$column6,


"g"=>$column7,


"h"=>$column8,


"i"=>$column9,


"j"=>$column10


);


 


$hello = rand($row["a"][0],$row["j"][9]);


echo "$hello";


 


print<<<HERE


 


<form method = "post"


 action = "">


<table border = "1">


 


HERE;


 


 


for ($i="a";$i<="j";$i++)


{


print "<tr>";


 


 


foreach ($row["$i"] as $pntRow)


{


 


print "<td><input type = 'checkbox' value = '$pntRow'/>$pntRow</td>\n";


 


 


 


print"</tr>\n";


} 


 


print "</table></form>";


print "<button type = 'submit'>Fire!</button>";


 


}


 


 


echo '<table width="300" height="300" border="1" align="center">';


 


for ( $row = 1; $row <= 10; $row++ ) 


{


	echo '<tr>';


 


 


	for( $col = 1; $col <= 10; $col++ ) 


	{


		echo '<td width="30" align="center">';


		echo ( isset($grid[$row][$col]) ? $grid[$row][$col] : ' ' );


		echo '</td>';


	}


	echo '</tr>';


} 


 


 


echo '</table>';


?>


 


 


<?php


 


{}


 


?>


 


 


 


<form method="post" action="" name="choice">


 


 


<input name="start_game" id="start_game" value="Start Game"


 


 


type="submit" src="game.png" name="image" width="100" height="150"><br>


 


 


</form>


 


<?php


 


{}


 


?>



 


 <p id="footer">Copyright © 2013 DeAnna Riddlespur</p>


 


</body>


</html>
Link to comment
https://forums.phpfreaks.com/topic/280127-parse-error-help-please/
Share on other sites

If you use an editor like Netbeans, it will highlight problems for you..

 

You haven't closed the curly brace for the very first if statement 

 

if (isset($_POST['start_game'])) {

 

Add that curly brace at the end of the file, or wherever the contents of the if finishes, and it will work.

 

Denno

that error, if you had searched for it, means that you have some opening php syntax that is not closed before the end of your file. this is generally due to a missing closing } but can also be due to a missing closing quote on a string...

 

even ignoring how the forum software messed up your posted code, you need to properly indent your code (all the lines of code that are between matching { } should be indented the same amount, this lets you see where there are missing }) and eliminate the excessive blank lines and white-space in it.

Archived

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

×
×
  • 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.