PHP - Undefined Index Array Problem

I am taking my first course in PHP and I found some logic I am using to build a Tic-Tac-Toe game.  However, for some reason the 0th position of the array is being ignored.  Here is my code


$box = array('', '', '', '', '', '', '', '', '');
if (isset($_POST["submitbtn"])) {
  $box[0] = $_POST["box0"];
$box[1] = $_POST["box1"];
  $box[2] = $_POST["box2"];
  $box[3] = $_POST["box3"];
  $box[4] = $_POST["box4"];
  $box[5] = $_POST["box5"];
  $box[6] = $_POST["box6"];
  $box[7] = $_POST["box7"];
$box[8] = $_POST["box8"];
  echo "<pre>";
    <form name="TicTacToe" method="post" action="test2.php"
                 for ($i=0; $i<=8; $i++) {
  printf('<input type ="text" name="box%s" value="%s">', $i, $box[$i]);
  if($i == 2 || $i == 5 || $i == 8){
    print('<br />');
          print('<input type="submit" name="submitbtn" value="Submit">');

Open in new window

Here is a screenshot of he error.

As you can see when I put 'a' into the first element of the array it is showing it in the second element.  I want to know how it can be corrected to be in the first element.

Please keep in mind I can't use techniques I haven't been taught so please keep it simple.

Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
<form name="TicTacToe" method="post" action="test2.php"
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you don' t close the <form> tag properly...
sharingsunshineAuthor Commented:
Looked all over for that problem.  Thanks for finding it so quickly
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.