Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Location
    Atlanta, ga
    Posts
    5
    Thanks
    4
    Thanked 0 Times in 0 Posts

    help with unexpected end error

    PHP Code:
    <?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] : '&nbsp;' );
            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) == '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($name01);
    }
    }
    $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] : '&nbsp;' );
            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 &copy; 2013 DeAnna Riddlespur & Gene Lau & Matthew Semple</p>
    </body>
    </html>
    <var><var></var></var>

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Can you post the code right around the line number the error gives?
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,026
    Thanks
    23
    Thanked 588 Times in 587 Posts
    Your code is hard to navigate, but here are a few things.
    Code:
    <var><var></var></var>
    After the end of the code.

    Two
    PHP Code:
    <?php {} ?>
    near the end of the file that don't seem connected to anything. Probably should be deleted.

    Can not find the closing tag for
    PHP Code:
    if(isset($_POST["start_game"]))

    After the heredoc
    PHP Code:
    HERE;       // THIS IS THE END OF THE HEREDOC
    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";

    This line
    PHP Code:
    foreach ($row["$i"] as $pntRow
    S/B

    PHP Code:
    foreach ($row as $pntRow
    But even removing the HTML code and fixing the above, still getting unexpected end of file error.
    Evolution - The non-random survival of random variants.

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,902
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Almost always caused by a missing right hand curly bracket. I'm taking a collection for all the poor orphaned left hand curly brackets ! If you have a decent text highlighting editer, I use SciTE, and you click on that bracket, it will be a different color than the rest.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #5
    New Coder
    Join Date
    Sep 2011
    Posts
    63
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by DrDOS View Post
    Almost always caused by a missing right hand curly bracket. I'm taking a collection for all the poor orphaned left hand curly brackets ! If you have a decent text highlighting editer, I use SciTE, and you click on that bracket, it will be a different color than the rest.
    Another great one is sublime, saved me a lot of time
    Lots of useful short cuts and its free!

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,026
    Thanks
    23
    Thanked 588 Times in 587 Posts
    @davidjones1990, does sublime give a fast method of displaying your code in a browser? I down loaded it but don't see a button or short cut to open firefox.
    Also can a user add a tool bar to this so we can just click icons to make sublime do things?

    @drDos, does SciTE have intellisense? I downloaded it but it had no help file.
    Evolution - The non-random survival of random variants.

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Quote Originally Posted by sunfighter View Post
    This line
    PHP Code:
    foreach ($row["$i"] as $pntRow
    S/B

    PHP Code:
    foreach ($row as $pntRow
    You did take into account the fact that is is a multidimensional array right?

    @roosnanie

    To be honest, your code is full of so many errors it's not really practical to even try and diagnose them all as we'd still be poking at shadows with many potential problems.

    What you need to do is start from scratch and test your code step by step.

    For instance this is the very first fault and it hasn't been picked up by anyone yet:
    PHP Code:
    <?php session_start() ?>
    There is no ; at the end of that line. Thats the first line and the rest don't get a lot better.

    You have a missing } at the end of your first if:
    if(isset($_POST['start_game']))
    {

    Then you have TWO of these:
    {}

    (thats are invalid syntax)

    Whenever you decide to create an if () conditional or anything else that has a matching opening / closing bracket such as the if itself, it's best to do the opener and closer first before putting in the content. Same applies to quotes.

    EG:

    PHP Code:
    //First step:
    if ()
       {

       }

    //Second step:
    if ($_POST[''])
       {

       }

    //Third step:
    if ($_POST['start_game'])
       {

       }

    //Fourth step:
    if ($_POST['start_game'])
       {
       
    //Something else here
       

    Doing it step by step like that ensures that you never mismatch your opening and closing pairs of icons.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #8
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,026
    Thanks
    23
    Thanked 588 Times in 587 Posts
    You did take into account the fact that is is a multidimensional array right?
    Nope.
    Didn't interpret the code. Started at the end and worked up til I decided there were too many errors
    The foreach didn't work as was, when I redid it I got output.
    Last edited by sunfighter; 07-14-2013 at 05:47 PM.
    Evolution - The non-random survival of random variants.

  • #9
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,902
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by sunfighter View Post

    @drDos, does SciTE have intellisense? I downloaded it but it had no help file.
    No, not that I know of, but it does have text highlighting for many languages.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •