Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title> PHP Tic Tac Toe</title>
- </head>
- <body>
- <?php
- //Variables
- //Boxes numbers in book-like order
- //The user input
- $value = $_POST['value'];
- //If the user hasn't hit submit, the boxes will be empty
- if(!isset($_POST['submit'])){
- $box1 = '-';
- $box2 = '-';
- $box3 = '-';
- $box4 = '-';
- $box5 = '-';
- $box6 = '-';
- $box7 = '-';
- $box8 = '-';
- $box9 = '-';
- }else{
- $box1 = $_POST['box1'];
- $box2 = $_POST['box2'];
- $box3 = $_POST['box3'];
- $box4 = $_POST['box4'];
- $box5 = $_POST['box5'];
- $box6 = $_POST['box6'];
- $box7 = $_POST['box7'];
- $box8 = $_POST['box8'];
- $box9 = $_POST['box9'];
- }
- //Read user input and act accordingly
- if(isset($_POST['submit'])){
- if($value == 'box1'){
- $box1 = 'X';
- }
- if($value == 'box2'){
- $box2 = 'X';
- }
- if($value == 'box3'){
- $box3 = 'X';
- }
- if($value == 'box4'){
- $box4 = 'X';
- }
- if($value == 'box5'){
- $box5 = 'X';
- }
- if($value == 'box6'){
- $box6 = 'X';
- }
- if($value == 'box7'){
- $box7 = 'X';
- }
- if($value == 'box8'){
- $box8 = 'X';
- }
- if($value == 'box9'){
- $box9 = 'X';
- }
- }
- echo '<table border="1px">';
- echo '<tr>';
- echo '<td>'.$box1.'</td>';
- echo '<td>'.$box2.'</td>';
- echo '<td>'.$box3.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.$box4.'</td>';
- echo '<td>'.$box5.'</td>';
- echo '<td>'.$box6.'</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.$box7.'</td>';
- echo '<td>'.$box8.'</td>';
- echo '<td>'.$box9.'</td>';
- echo '</tr>';
- echo '</table>';
- ?>
- <br>
- <form method='POST' action='<?php echo $_SERVER['PHP_SELF'];?>'>
- <input type='text' name='value'>
- <input type='hidden' value= "<?php echo $turn;?>" name='turn'>
- <input type='hidden' value= "<?php echo $box1;?>" name='box1'>
- <input type='hidden' value= "<?php echo $box2;?>" name='box2'>
- <input type='hidden' value= "<?php echo $box3;?>" name='box3'>
- <input type='hidden' value= "<?php echo $box4;?>" name='box4'>
- <input type='hidden' value= "<?php echo $box5;?>" name='box5'>
- <input type='hidden' value= "<?php echo $box6;?>" name='box6'>
- <input type='hidden' value= "<?php echo $box7;?>" name='box7'>
- <input type='hidden' value= "<?php echo $box8;?>" name='box8'>
- <input type='hidden' value= "<?php echo $box9;?>" name='box9'>
- <input type="submit" value="Turn" name="submit">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment