Solved

PHP Parse Error

Posted on 2016-08-31
6
49 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 110

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 2

Author Closing Comment

by:erzoolander
ID: 41778764
Gracias!
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

617 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