Error:
Parse error: syntax error, unexpected T_VARIABLE in
D: \ Work \ OpenServer \ OpenServer \ domains \ laba \ game.php on line 7
What’s wrong with this code?
& lt;? php
session_start ();
if (isset ($ _ POST ['num'])) {
$ number = (int) $ _POST ['num'];
if (! isset ($ _ SESSION ['answer'])
$ _SESSION ['answer'] = mt_rand (1, 10);
if (! isset ($ _ SESSION ['attempts']))
$ _SESSION ['attempts'] = 1;
if ($ number & gt; $ _SESSION ['answer']) {
echo 'Too big.';
$ _SESSION ['attempts'] ++;
}
elseif ($ number & lt; $ _SESSION ['answer']) {
echo 'Too small.';
$ _SESSION ['attempts'] ++;
}
else {
echo 'Hooray! You guessed right after & lt; b & gt; ', $ _SESSION [' attempts '],' & lt; / b & gt; attempts! ';
session_destroy ();
}
}
? & gt;
Something tells me that there are several problem areas
Answer 1, authority 100%
Well, I’ll write him the answer how to write INTO not be mistaken in the elementary:
- Code formatting when formatting, 4 spaces are used in the context of the operator, for example, your code will look like this
if
andelse
statements must contain{}
control constructs
result:
& lt;? php
session_start ();
if (isset ($ _ POST ['num'])) {
$ number = (int) $ _POST ['num'];
if (! isset ($ _ SESSION ['answer']) {
$ _SESSION ['answer'] = mt_rand (1, 10);
}
if (! isset ($ _ SESSION ['attempts'])) {
$ _SESSION ['attempts'] = 1;
}
if ($ number & gt; $ _SESSION ['answer']) {
echo 'Too big.';
$ _SESSION ['attempts'] ++;
} elseif ($ number & lt; $ _SESSION ['answer']) {
echo 'Too small.';
$ _SESSION ['attempts'] ++;
} else {
echo 'Yeah! You answered after & lt; b & gt; ', $ _SESSION [' attempts '],' & lt; / b & gt; attempts! ';
session_destroy ();
}
}
? & gt;