Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix syntax error, unexpected T_IF error in php? [closed]

Tags:

syntax

php

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; } 
like image 911
STEEL Avatar asked Jun 02 '12 06:06

STEEL


People also ask

How to fix the parse error syntax error unexpected in PHP?

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.

What is syntax error in PHP?

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.

What is syntax error unexpected?

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.


2 Answers

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 :)

like image 181
Ja͢ck Avatar answered Sep 21 '22 20:09

Ja͢ck


add semi-colon the line before:

$total_pages = ceil($total_result / $per_page); 
like image 37
Robbie Avatar answered Sep 22 '22 20:09

Robbie