Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 51
  • Last Modified:

PHP Parse Error

I'm getting a parsing error apparently due to a misplaced bracket - but don't quite understand why.

Here's the code:

public function listAgents() {
		include("db_connect.php");
	$query = "SELECT * FROM tblagent t1
	LEFT JOIN tblcompany t2 on t2.company_id = t1.company_id";
	if ($_POST['compname'] != "") {
		$query .= " WHERE t2.company_id = '".$_POST['compname']."' ";
	}
	if ($_POST['agentname'] != "") {
		$query .= " WHERE t1.agent_name LIKE '%".$_POST['agentname']."%' ";
	}
	$query .= " ORDER BY agent_name ASC";
	$result = $con->query($query);
	if ($result->num_rows > 0) {
		?>
        <table>
        <tr>
        <td>Agent Name</td>
        <td>Company</td>
        <td>Active</td>
        <td>Action</td>
        <td>Sign In</td>
        <td>Delete</td>
        </tr>
        <?
    // output data of each row
    while($row = $result->fetch_assoc()) {
		?>
        <tr>
        <?php 
		echo ("<td>".$row['agent_name']."</td>");
		echo ("<td>".$row['company_name']."</td>");
		echo ("<td>".$row['pactive']."</td>");
		echo ("<td>Edit</td>");
		echo ("<td>Yes</td>");
		echo ("<td>Yes</td>");
       
    ?> </tr><?php };
	?></table>
    <?php
} else {
    echo "0 results";
}
$con->close();
	}

Open in new window


Apparently it's down around the } else { clause around line 40.  

What am I missing?  The preceding bracket terminates the while loop...  then the next (where it appears to be occurring) terminates the if condition.  

Thanks in advance!
0
erzoolander
Asked:
erzoolander
4 Solutions
 
Olaf DoschkeSoftware DeveloperCommented:
I think it's because of line 24: <? should of course be <?php

Bye, Olaf.
0
 
zephyr_hex (Megan)DeveloperCommented:
Line 24:  shouldn't it be <?php
0
 
erzoolanderAuthor Commented:
Weird, yep, okay that was it.

As a correlated question...just out of curiosity (I'll give you both the points...lol)  The error was only discovered when I moved to a new server.  The previous one gave no glitch on that.  Any idea why one server's PHP might let it pass - but another glitch out?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Olaf DoschkeSoftware DeveloperCommented:
There's a php.ini option of "short_open_tag", It's recommended to not use this. See http://php.net/manual/en/language.basic-syntax.phptags.php

Bye, Olaf.
0
 
Ray PaseurCommented:
The PHP short open tag is an anti-practice because it depends on a configuration setting.  As you have now seen, different PHP installations handle the short open tag differently, so we avoid it and use the full <?php tag instead.
0
 
erzoolanderAuthor Commented:
Gracias!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now