Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP - Undefined Index Array Problem

Posted on 2016-07-21
3
Medium Priority
?
135 Views
Last Modified: 2016-07-21
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

<?php

$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>";
print_r($box);
}
 ?>
<html>
  <head>
    <title>Tic-Tac-Toe</title>
  </head>
  <body>
    <form name="TicTacToe" method="post" action="test2.php"
          <?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">');
          ?>
          
    </form>
  </body>
</html>

Open in new window


Here is a screenshot of he error.
https://gyazo.com/500b6db6b2ff591c9d80b2f21aa03370

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.

Thanks
0
Comment
Question by:sharingsunshine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41722959
you don' t close the <form> tag properly...
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 41722960
<form name="TicTacToe" method="post" action="test2.php"
>
<?php
0
 

Author Closing Comment

by:sharingsunshine
ID: 41722974
Looked all over for that problem.  Thanks for finding it so quickly
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question