Solved

PHP Parse Error

Posted on 2016-08-31
6
33 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
Comment Utility
I think it's because of line 24: <? should of course be <?php

Bye, Olaf.
0
 
LVL 42

Assisted Solution

by:zephyr_hex
zephyr_hex earned 125 total points
Comment Utility
Line 24:  shouldn't it be <?php
0
 
LVL 1

Author Comment

by:erzoolander
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 250 total points
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
Comment Utility
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
Comment Utility
Gracias!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now