dimanche 25 février 2018

PHP print message if the mark posted from previous page is not same with the input value that player input

I am struggling with php now. What I am trying to do is to put the mark wherever in the block of input when selecting the second turn and moving to the next page. But it is not showing anything for now when moving to next page. Here is my code. I really appreciate everybody's help! What I am trying to do is adding something like this. if(isset($_POST["start"])){if($senkou=="second" && $mark=="×"){$block='×';} if($senkou=="second" && $mark=="○"){$block='○';}

<?php
session_start();
if(isset($_POST["start"])){
$namae=$_POST['namae'];
$senkou=$_POST['senkou'];
$mark=$_POST['mark'];
$_SESSION['namae']=$namae ;
$_SESSION['senkou']=$senkou ;
$_SESSION['mark']=$mark ;
}else{
$namae=$_SESSION['namae'];
$senkou=$_SESSION['senkou'];
$mark=$_SESSION['mark'];
}
$block=array('','','','','','','','','');
if(isset($_POST["send"])){
$block[0]=$_POST["block0"];
$block[1]=$_POST["block1"];
$block[2]=$_POST["block2"];
$block[3]=$_POST["block3"];
$block[4]=$_POST["block4"];
$block[5]=$_POST["block5"];
$block[6]=$_POST["block6"];
$block[7]=$_POST["block7"];
$block[8]=$_POST["block8"];

$blank=0; 
for ($i=0; $i<=8; $i++){
if($block[$i]==''){
$blank=1;
}
if($blank== 1 && $winner=='n'){
$i=rand() % 8 ;
while($block[$i] !=''){
$i=rand() % 8 ;
}
if ($mark=="○"){
$block[$i]='×';
}
if ($mark=="×"){
$block[$i]='○';
}
}
}
?>
<html>
<head>
<title>TicTacToe</title>       
</head>
<body class="body">
<input type="hidden" id="postedmark" value="<?php echo $mark ?>">
name:<?php echo $namae ;?>
who goes first:<?php echo $senkou ;?>
mark:<?php echo $mark ?>
<form name="myform" method="post" action="tttgames2.php">
<?php
for ($i=0; $i<=8; $i++){
printf('<input type="text" name="block%s" value="%s" id="block" 
onchange="check()">',$i,$block[$i]);
if($i==2 || $i==5 || $i==8){
print('<br>');
}
}
print('<input type="submit" class="send" name="send" id="send" value="send">');
} 

?>
</form>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire