Solved

PHP Parse Error

Posted on 2016-08-31
6
41 Views
Last Modified: 2016-08-31
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
Comment
Question by:erzoolander
6 Comments
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 250 total points
ID: 41778704
I think it's because of line 24: <? should of course be <?php

Bye, Olaf.
0
 
LVL 43

Assisted Solution

by:zephyr_hex (Megan)
zephyr_hex (Megan) earned 125 total points
ID: 41778705
Line 24:  shouldn't it be <?php
0
 
LVL 1

Author Comment

by:erzoolander
ID: 41778721
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 250 total points
ID: 41778746
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
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
ID: 41778750
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
 
LVL 1

Author Closing Comment

by:erzoolander
ID: 41778764
Gracias!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question