0
   it says syntax error t_else, what could be the problem? 

it really is making me crazy for finding what did i do wrong in this code what could be myy mistake here?

<?php
include("../mysql_connect.php");
if (isset($_POST['search_form'])) {
    $page1 = $_GET['page'];
    if ($page1 == "" || $page1 == 1) {
        $page1 = 0;
    }
    else {
        $page1 = ($page1 * 5) - 5;
    }
    $query = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)) {
        ?>
        <table class="table table-hover" border="2">
            <col width="50%"></col>
            <col width="40%"></col>
            <col width="20%"></col>
            <tr>
                <td rowspan="3">
                    a href="news_view.php?id=<?php echo $row['news_id']; ?>">
                    <img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300" width="500">
                    </a>
                </td>
                <td>Title: <?php echo $row['news_title']; ?></td>

            </tr>
            <tr>
                <td>Author: <?php echo $row['news_author']; ?></td>
            </tr>

            <tr>
                <td>Date: <?php echo $row['news_date_filed']; ?></td>
            </tr>
            </thead>
        </table>
        <?php
    }
    $query1 = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
    $result1 = mysql_query($query1);
    $row1 = mysql_num_rows($result1);
    $pagecount = $row1 / 5;
    $pagecount = ceil($pagecount);

    for ($count = 1; $count <= $pagecount; $count++) {
        ?>

        <a href="news.php?page=<?php echo $count; ?>"><?php echo $count ?></a>

        <?php
    }
}
else{
    $page1 = $_GET['page'];
    if ($page1 == "" || $page1 == 1) {
        $page1 = 0;
    }
    else {
        $page1 = ($page1 * 5) - 5;
    }
    $query = "select * from tbl_news where news_status='Active' limit $page1,5";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)) {
        ?>
        <table class="table table-hover" border="2">
            <col width="50%"></col>
            <col width="40%"></col>
            <col width="20%"></col>
            <tr>
                <td rowspan="3">
                    <a href="news_view.php?id=<?php echo $row['news_id']; ?>">
                        <img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300"
                             width="500">
                    </a>
                </td>
                <td>Title: <?php echo $row['news_title']; ?></td>

            </tr>
            <tr>
                <td>Author: <?php echo $row['news_author']; ?></td>
            </tr>

            <tr>
                <td>Date: <?php echo $row['news_date_filed']; ?></td>
            </tr>
            </thead>
        </table>
        <?php
    }
    ?>
    <?php
    $query1 = "select * from tbl_news where news_status='Active'";
    $result1 = mysql_query($query1);
    $row1 = mysql_num_rows($result1);
    $pagecount = $row1 / 5;
    $pagecount = ceil($pagecount);

    for ($count = 1; $count <= $pagecount; $count++) {
        ?>

        <a href="news.php?page=<?php echo $count; ?>"><?php echo $count ?></a>

        <?php # code...
    }
}
?>  

here is the full code, of what errror gives me, please help me guys it takes me a a lot of time having this kind of problem i already tried everything i could but maybe you guys could me solve my problem hahahaha it really drained my mind here , im already mindblown on what is the my currently facing problem

Erik A
  • 31,639
  • 12
  • 42
  • 67
tenteren
  • 1
  • 4
  • 1
    mysql_* functions are deprecated as of PHP 5.5.0, and removed as of PHP 7.0.0. Switch your code to use [PDO](https://secure.php.net/manual/en/pdo.prepared-statements.php) or [mysqli](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead. – aynber Aug 15 '17 at 13:57
  • 1
    Take out the `?> – aynber Aug 15 '17 at 13:58
  • No wonder there is an error. I could never keep track of all the open and close tags. Do you know where this error is? What line? – Andreas Aug 15 '17 at 14:03
  • the error that it is givving to me is Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\MPTRACKING\home\news.php on line 109 – tenteren Aug 15 '17 at 14:05
  • its at the else condition of my first if – tenteren Aug 15 '17 at 14:06
  • It's in the middle of ` – aynber Aug 15 '17 at 14:09
  • I really recommend using a good IDE with syntax checking and code highlighting. My IDE (PHPStorm) pointed out all of the spots with errors, though it had problems explaining why *that* bit was throwing the error. – aynber Aug 15 '17 at 14:11
  • So since I can't use my answer, i'll give you a quick overview here... Your main problem when you want to debug this is your formatting, you will struggle to see where one conditional ends and another begins. I would advise using the other form of conditions if you really have to mix HTML and PHP in a single file. i.e. rather than `if ($condition) { // code }` you would use `if ($condition): // code endif;`. This will allow you to easily match up your code blocks. You should also watch your indentation, it'll help you spot rogue elements. i.e. https://pastebin.com/w5em7KPi – Mikey Aug 15 '17 at 14:42

2 Answers2

-1

You are missing < at the a tag inside the first while loop (exactly on line 21 when I copy/paste your code). That might be the reason it doesn't recognize the else statement, because it can't get to it properly.

MirzaS
  • 514
  • 3
  • 16
-1

try this code. may be it resolve your problem. I have corrected some syntax mistake in your code.

 <?php
                  include("../mysql_connect.php");
                    if (isset($_POST['search_form'])) {
                      $page1=$_GET['page'];
                      if ($page1=="" || $page1==1) {
                          $page1=0;
                      }
                      else{
                          $page1=($page1*5)-5;
                      }
                      $query="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
                      $result=mysql_query($query);
                      while ($row=mysql_fetch_array($result)) {
                  ?>
                          <table class="table table-hover" border="2">
                                  <col width="50%"></col>
                                  <col width="40%"></col>
                                  <col width="20%"></col>
                              <tr>
                                <td rowspan="3">
                                    <a href="news_view.php?id=<?php echo $row['news_id'];?>">
                                       <img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
                                    </a>
                                </td>
                                  <td>Title: <?php echo $row['news_title'];?></td>

                              </tr>
                              <tr>
                                  <td>Author: <?php echo $row['news_author'];?></td>
                              </tr>

                              <tr>
                                  <td>Date: <?php echo $row['news_date_filed'];?></td>
                          </tr>
                              </thead>
                      </table>       
                  <?php 
                      }
                      $query1="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
                      $result1=mysql_query($query1);
                      $row1=mysql_num_rows($result1);
                      $pagecount=$row1/5;
                      $pagecount=ceil($pagecount);

                      for ($count=1; $count <= $pagecount ; $count++) { 


     ?>

                                  <a href="news.php?page=<?php echo $count;?>"><?php echo $count?></a>

                <?php  
                      }
                    }else{
                          $page1=$_GET['page'];
                          if ($page1=="" || $page1==1) {
                              $page1=0;
                          }
                          else{
                              $page1=($page1*5)-5;
                          }
                          $query="select * from tbl_news where news_status='Active' limit $page1,5";
                          $result=mysql_query($query);
                          while ($row=mysql_fetch_array($result)) {
                                            ?>
                      <table class="table table-hover" border="2">
                                      <col width="50%"></col>
                                      <col width="40%"></col>
                                      <col width="20%"></col>
                                  <tr>
                                    <td rowspan="3">
                                        <a href="news_view.php?id=<?php echo $row['news_id'];?>">
                                          <img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
                                        </a>
                                    </td>
                                      <td>Title: <?php echo $row['news_title'];?></td>

                                  </tr>
                                  <tr>
                                      <td>Author: <?php echo $row['news_author'];?></td>
                                  </tr>

                                  <tr>
                                      <td>Date: <?php echo $row['news_date_filed'];?></td>
                              </tr>
                                  </thead>
                          </table>       
                      <?php 
                          }
                          $query1="select * from tbl_news where news_status='Active'";
                          $result1=mysql_query($query1);
                          $row1=mysql_num_rows($result1);
                          $pagecount=$row1/5;
                          $pagecount=ceil($pagecount);

                          for ($count=1; $count <= $pagecount ; $count++) { 
                      ?>

                                      <a href="news.php?page=<?php echo $count;?>"><?php echo $count?></a>

                      <?php        # code...
                          }
                     }                           
                      ?>
Mahmood Sanjrani
  • 108
  • 3
  • 19
  • This does **not** answer the question in a _useful way_. **why** do you believe this is the answer? **how** does it work? Simply telling someone to _change their code_ without any context or meaning does not help them learn what they did wrong, and is also not as useful for future readers. – GrumpyCrouton Aug 15 '17 at 14:07
  • **Please**, don't use `mysql_*` functions for new code. They are no longer maintained and the community has begun the [deprecation process](http://news.php.net/php.internals/53799), and `mysql_*` functions have been officially removed in PHP 7. Instead you should learn about [prepared statements](https://en.wikipedia.org/wiki/Prepared_statement) and use either `PDO` or `mysqli_*`. If you can't decide, [this article will help to choose your best option](http://php.net/manual/en/mysqlinfo.api.choosing.php). – GrumpyCrouton Aug 15 '17 at 14:07
  • [Little Bobby](http://bobby-tables.com/) says **[you are at risk for SQL Injection Attacks](https://stackoverflow.com/q/60174/)**. Learn about [Prepared Statements](https://en.wikipedia.org/wiki/Prepared_statement) for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even **[escaping the string](https://stackoverflow.com/q/5741187)** is not safe! I recommend `PDO`, which I [wrote a function for](https://stackoverflow.com/a/45514591) to make it extremely **easy**, very **clean**, and way more **secure** than using non-parameterized queries. – GrumpyCrouton Aug 15 '17 at 14:08
  • can i know what did u do? – tenteren Aug 15 '17 at 14:08
  • @GrumpyCrouton I have edited my answer, and i tried to explain. sir. – Mahmood Sanjrani Aug 15 '17 at 14:11
  • @MahmoodSanjrani Stating "I fixed a syntax error" does _not_ explain the change you made, why you made it, why it works, how it helps, or really anything as the OP can't even see _where_ the syntax error was. – GrumpyCrouton Aug 15 '17 at 14:12
  • @tenteren I have edited my answers. please check let me know if it didn't solve your problem. – Mahmood Sanjrani Aug 15 '17 at 14:12
  • Also, You shouldn't answer duplicate questions. – GrumpyCrouton Aug 15 '17 at 14:13