Parse error: syntax error, unexpected T_IF in view.php on line 27
I really dont see any problem in my code, why this is happening, please help. Im a beginner in PHP
Where my LINE 21 is >> if(isset($_GET['page']) && is_numeric($_GET['page']))
if ($result = $mysqli->query("SELECT * FROM players ORDER BY id")) { if ($result->num_rows > 0) { $total_result = $result->num_rows; $total_pages = ceil($total_result / $per_page) if(isset($_GET['page']) && is_numeric($_GET['page'])) { $show_page = $_GET['page']; if ($show_page > 0 && $show_page <= $total_pages) { $start = ($show_page - 1) * $per_page; $end = $start + $per_page; } else { $start = 0; $end = $per_page; } } else { $start = 0; $end = $per_page; } //display paginations echo "<p> View pages: "; for ($i=1; $i < $total_pages; $i++) { if (isset($_GET['page']) && $_GET['page'] == $i) { echo $i . " "; } else { echo "<a href='view-pag.php?$i'>" . $i . "</a> | "; } } echo "</p>"; } else { echo "No result to display."; } } else { echo "Error: " . $mysqli->error; }
To solve the missing parenthesis error in PHP, the code has to be checked from the beginning to search for it. One way to avoid errors is to use proper indentation in the code. Once all the parentheses in the code have been set correctly, parse error: syntax error, unexpected $end will be fixed.
If the PHP code contains a syntax error, the PHP parser cannot interpret the code and stops working. For example, a syntax error can be a forgotten quotation mark, a missing semicolon at the end of a line, missing parenthesis, or extra characters.
Syntax Error – This error is caused by an error in the PHP structure when a character is missing or added that shouldn't be there. Unexpected – This means the code is missing a character and PHP reaches the end of the file without finding what it's looking for.
PHP parser errors take some getting used to; if it complains about an unexpected 'something' at line X, look at line X-1 first. In this case it will not tell you that you forgot a semi-colon at the end of the previous line , instead it will complain about the if
that comes next.
You'll get used to it :)
add semi-colon the line before:
$total_pages = ceil($total_result / $per_page);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With