Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    T_ENDIF error.. going crazy.

    Hey guys, first time post here and hopefully I can help out in the front-end side of this forum!

    I have a bit of a strange situation going on here. Locally (through mamp) the website loads fine (perfectly actually) and I find zero errors, however going live I face the infamous T_ENDIF error according to my error log. I had the code working remotely however made some changes to only the HTML, uploaded and like as if it was black magic I was faced with the error.

    I proceeded to trouble shoot and I had the document which was orginally working before I edited the HTML and uploaded that and it worked perfectly, I then took the working document and in my editor hit the space bar, again black magic the working document then gave the same error, I hit cmd+z to undo the spacebar, re-uploaded and still had zero luck. Is it just me or am I going insane? Here is my code:

    PHP Code:
    <?php
    if($post $_GET["id"]) {
       
    echo 
    "<div class='engage-search-result'>Search Result:</div>";
        
    $q "SELECT * FROM questions WHERE id = '$post'";
    $r mysql_query($q);

    if(
    mysql_num_rows($r)>0):
    while(
    $row mysql_fetch_assoc($r)):
    $net_vote $row['votes_up'] - $row['votes_down'];
    ?>

    <div class='entry'>    
    <div class='q_container'>

    <div class='left'>
    <a href='javascript:;' class='vote_up' id='<?php echo $row['id']; ?>'>Up</a>
    <span class='votes_count' id='votes_count<?php echo $row['id']; ?>'>
    <?php echo $net_vote.""?>
    </span>
    <a href='javascript:;' class='vote_down' id='<?php echo $row['id']; ?>'>Down</a>
    </div><!--// left-->

    <div class='right'>
    <span class='link'>
    <?php echo "<a href='engage.php?id=".$row['id']."'>".$row['question']."</a>"?><br><?php echo $row['categorey']; ?>
    <br><br>
    <?php  echo "<div class='fb-comments' data-href='http://sitehere.com'  data-num-posts='2'></div>"?>
    </span><!--// link (span)-->
    </div><!--// right-->
    </div><!--// q_container-->
    </div><!--// entry-->
    <?php
    endwhile;
    endif;
    ?>

    <?php
    } else {
        
    $q "SELECT * FROM questions WHERE verified = 'y'";
    $r mysql_query($q);

    if(
    mysql_num_rows($r)>0):
    while(
    $row mysql_fetch_assoc($r)):
    $net_vote $row['votes_up'] - $row['votes_down'];
    ?>

    <div class='entry'>  
    <div class="q_container">
    <div class='left'>
    <a href='javascript:;' class='vote_up' id='<?php echo $row['id']; ?>'>Up</a>
    <span class='votes_count' id='votes_count<?php echo $row['id']; ?>'>
    <?php echo $net_vote.""?>
    </span>
    <a href='javascript:;' class='vote_down' id='<?php echo $row['id']; ?>'>Down</a>
    </div><!--// left-->

    <div class='right'>
    <span class='link'>
    <?php  echo "<a href='engage.php?id=".$row['id']."'>".$row['question']."</a>"?><br>#<?php echo $row['categorey']; ?> </a>
    <br><br>
    <?php  echo "<div class='fb-comments' data-href='http://www.sitehere.com/engage.php?id=".$row['id']."'  data-num-posts='1'></div>"?>
    </span><!--// link (span)-->
    </div><!--// right-->

    </div><!--// q_container-->
    </div><!--// entry-->
    <?php
    endwhile;
    endif;
    }
    ?>
    I call my DB connection at the top of the browser using include, the error log shows the error on line 1 where my DB connection is held. I am only a begginer with PHP and I am aware I am not using PDO.

    Any help would be greatly appreciated.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by nicoscodes View Post
    I have a bit of a strange situation going on here.
    Whoa slow down there champ! I don't know why but many inexperienced php coders come here claiming to have a 'strange' error not realising that they're actually not exactly experts and still make mistakes. There is nothing 'strange' about coding errors. They happen and even the more experienced make blunders.

    Quote Originally Posted by nicoscodes View Post
    going live I face the infamous T_ENDIF error according to my error log.
    And which one would that be?
    Unexpected T_ENDIF, expected <something>
    <something> expected but T_ENDIF found...

    Something else?

    IF you want help, you need to be farmore specific instead of doing a dump n run with your code.

    Also while it seems the best thing to do at first, mixing your php and html is a bad idea. It's messy and harder to debug. Run your php logic first, create your variables and bits of html and then put them into the html last.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    I've just looked at your if conditionals (stripping out everything in between):

    PHP Code:
     <?php
    if($post $_GET["id"]) {

    if(
    mysql_num_rows($r)>0):

    endif;
    ?>

    <?php
    } else {

    if(
    mysql_num_rows($r)>0):

    endif;
    }
    ?>
    While the immediate fault isn't glaring me in the face, your use of the { and } and the 'endif' is.

    Pick one and stick to it. Either { and } OR endif. Don't use the two and mix them up or you'll confuse yourself.

    Also format things better so that you know which { belongs to which }. You can find a link with advice about coding styles in my signature.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •