Page 1 of 1

Parse error: parse error, unexpected '>'

Posted: Fri May 31, 2002 3:44 am
by Paul Oertel
I am a beginner at PHP and I would appreciate some help in getting through this rough spot. I am getting parser errors in my echo statements.

Parse error: parse error, unexpected '>' in results.php on line 41

Line 41 is as follows:

echo "<p>Number of events found: ".$num_results."</p>";

I looked at all of the code leading up to this line and I don't see any problems with unmatched "<". My mistake is probably something simple that I am overlooking.

If someone could spot my mistake I would greatly appreciate it.

The full code is as follows.

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Mimi System - Search Page&lt;/title&gt;
&lt;style type="text/css"&gt;
.event {position:absolute; top:40px; right:10px;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php

$eventid = $_POST&#1111;'eventid'];
$computer = $_POST&#1111;'computer'];
$log = $_POST&#1111;'log'];

trim($eventid);
trim($computer);
trim($log);

@ $db = mysql_connect("localhost", "isa", "isa");

if (!$eventid || !$computer)
{
	echo "You have not entered in sufficient search criteria. Please go back and try again.";
	exit;
}

if (!$db)
{
	echo "Error: Could not connect ot database. Please try again later.";
	exit;
}

mysql_select_db("logdb");

$query="SELECT * FROM ".$log." where computer=".$machine." and eventid=".$eventid.";

$result = mysql_query($query);
$num_results = mysql_num_rows($result);
  
 echo "&lt;p&gt;Number of events found: ".$num_results."&lt;/p&gt;";

for ($i=0; $i &lt; $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "&lt;p&gt;&lt;strong&gt;".($i+1).". Log: ";
echo htmlspecialchars(stipslashes($row&#1111;log]));
echo "&lt;/strong&gt;&lt;br&gt;Event ID: ";
echo htmlspecialchars(stripslashes($row&#1111;eventid]));
echo "&lt;/strong&gt;&lt;br&gt;Computer: ";
echo htmlspecialchars(stripslashes($row&#1111;computer]));
echo "&lt;/p&gt;"
}

&lt;/body&gt;
&lt;/html&gt;

Posted: Fri May 31, 2002 4:05 am
by volka

Code: Select all

&lt;?php
...
echo htmlspecialchars(stripslashes($row&#1111;computer])); 
echo "&lt;/p&gt;";
}
&gt;?
&lt;/body&gt;&lt;/html&gt;
you forgot the ; and have to put the direct outputs outside the <?php ... ?> block

Parse error: parse error, unexpected '>'

Posted: Fri May 31, 2002 4:47 am
by Paul Oertel
Volka,

Thanks for pointing out the error but that isn't what is causing the problem at line 41.

Paul

Posted: Fri May 31, 2002 5:41 am
by twigletmac
Parse errors occur when PHP can no longer run the script so the generally appear on a line before the one cited in the message. In your case the error is most likely the one on line 36:

Code: Select all

$query= "SELECT * FROM ".$log." where computer=".$machine." and eventid=".$eventid.";
At the end of that line you open a set of double quotes but don't close them (and don't need them), try changing the line to:

Code: Select all

$query= "SELECT * FROM ".$log." where computer=".$machine." and eventid=".$eventid;
and see what happens.

Hope it helps,
Mac

Posted: Fri May 31, 2002 12:55 pm
by mikeq
Also because you use " you don't need to do the concatenation thing, just do this

Code: Select all

&lt;?php
$query= "SELECT * FROM $log where computer=$machine and eventid=$eventid";
?&gt;
as an aside this query will only return a result set if computer and eventid are numbers.

Parse error: parse error, unexpected '>'

Posted: Fri May 31, 2002 10:04 pm
by Paul Oertel
Thanks to everyone who gave me advice. I will try it the corrections when I get back to work on Monday.

Thanks.
Paul