Solved

PHP Parse Error

Posted on 2016-08-31
6
39 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 42

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
<? versus <?php 5 37
phpmailer in WHILE loop - weird results 10 29
Checking if varaible is empty 6 31
array_values - reorder after unset? 5 12
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

867 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

22 Experts available now in Live!

Get 1:1 Help Now