Page 1 of 1

Parse error: syntax error, unexpected T_ECHO, expecting

Posted: Wed Jul 29, 2009 6:32 pm
by tobimichigan
Here's my table
CREATE TABLE `yearly_reports` (
`id` int(11) NOT NULL auto_increment,
`name` char(10) NOT NULL,
`department` char(60) NOT NULL,
`pfno` char(10) NOT NULL,
`savings` varchar(255) NOT NULL,
`shares` varchar(255) NOT NULL,
`outloanbal` varchar(255) NOT NULL,
`loanrepaid` varchar(255) NOT NULL,
`loanint` varchar(255) NOT NULL,
`essenco` text NOT NULL,
`month` text NOT NULL,
`Year` varchar(234) NOT NULL,
`date` date NOT NULL,
`session` double NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

Now I have actually successfully inserted data into my table. I just want to display it neatly on a table. But I keep getting this error:

Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in C:Year_Summary.php on line 48

Code: Select all

<?php
session_start();
 
if (!$_SESSION["adminok"])
{
//user not logged in, redirect to login page
header("Location:Admin_Login.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Year Summary</title>
</head>
 
<body>
<?php
echo ("<p>Admin | <a href='Monthly_Post.php'>Monthly Update</a> |<a href='Monthly_Summary.php'>Monthly Summary | <a href='Year_Summary.php'>Year Summary</a> | <a href='Logout.php'>Logout</a></p>");
?>
<?php
include ("cn.php");
//fetch our page number from the query string
//the URL should look something like
//name_meanings.php?page=4
$page = $_GET['page'];
//define how many records we want to show per page
$records_per_page = 15;
if(!filter_var($page, VALIDATE_INT, 1))
  $page=1;   
echo "<h3>Showing results for page $page</h3>";
//calculate the offset value to start counting from
//in the MySQL query. To do this, we multiply the page
//number, minus one, by the number of records we want
//to show per page
//e.g. for page 1 - Our starting record will be (1-1)*30
$offset = ($page-1) * $records_per_page;
$result = mysql_query("SELECT * FROM yearly_reports ORDER BY pfno ASC LIMIT $offset, $records_per_page");
 
if($row = mysql_fetch_array($result)){
  do{
echo ("<table border='0' cellspacing='2' cellpadding='2'>");
echo ("<tr>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["pfno"]}</font></td>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["name"]}</font></td>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["department"]}</font></td>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["loanint"]}</font></td>")
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["loanrepaid"]}</font></td>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["outloanbal"]}</font></td>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["savings"]}</font></td>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["shares"]}</font></td>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["essenco"]}</font></td>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["month"]}</font></td>");
echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["Year"]}</font></td>");
echo("</tr></br>");
    
  } while($row = mysql_fetch_array($result));  
}
echo "</table>";
 
echo "<p>Navigation</p>";
$count_result = mysql_query("SELECT (*) FROM yearly_reports");
$count_row = mysql_fetch_array($count_result);
//fetch the total number of rows in the table
$count = $count_row["COUNT(*)"];
//we will use this information to build our navigation list
for($i=1; $i<=$count/$records_per_page; $i++){
  echo "<a href='Year_Summary.php?page=$i'>$i</a>";
  //output a little symbol (|) to seperate the links
  //but not for the last link
  if($i!=$records_per_page)
    echo " | ";
}
?>
 
 
</body>
</html>
 
Where line 48= echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["loanrepaid"]}</font></td>");

Is there something missing here?

Re: Parse error: syntax error, unexpected T_ECHO, expecting

Posted: Wed Jul 29, 2009 6:43 pm
by McInfo
Line 47 is missing a semicolon at the end.

Code: Select all

echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["loanint"]}</font></td>") // Missing semicolon
Also, <font> is deprecated in favor of CSS.

And add "=php" to the code tag for PHP code.

Code: Select all

[code=php]
[/code]
Edit: This post was recovered from search engine cache.

Re: Parse error: syntax error, unexpected T_ECHO, expecting

Posted: Wed Jul 29, 2009 6:57 pm
by tobimichigan
McInfo wrote:Line 47 is missing a semicolon at the end.

Code: Select all

echo("<td><font face='Arial, Helvetica, sans-serif'> {$row["loanint"]}</font></td>") // Missing semicolon
Also, <font> is deprecated in favor of CSS.

And add "=php" to the code tag for PHP code.
Please could you kindly come clear on "add=php" to the code tag 4 php code, what's that?

Re: Parse error: syntax error, unexpected T_ECHO, expecting

Posted: Wed Jul 29, 2009 7:04 pm
by McInfo
I was referring to the BBCode tags in your post. Right now, the code in your post is not syntax-highlighted.

To get the syntax highlighting, you need to change

Code: Select all

[code=text]
[/code]to

Code: Select all

[code=php]
[/code]
The difference:

Code: Select all

<?php
echo 'This is an example of code with no syntax highlighting.';
?>

Code: Select all

<?php
echo 'This is an example of code that is syntax-highlighted.';
?>
Edit: This post was recovered from search engine cache.

Re: Parse error: syntax error, unexpected T_ECHO, expecting

Posted: Wed Jul 29, 2009 7:12 pm
by tobimichigan
Yea, u're right...there's a sign of improvement. That Parse-error is gone now...however there's a new kind of error. The table displays quite neatly now, but at the top of my page it says:

Warning: filter_var() expects parameter 2 to be long, string given in C:\Year_Summary.php on line 29

then at the bottom it says:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Year_Summary.php on line 63

What's the way out of this?

Re: Parse error: syntax error, unexpected T_ECHO, expecting

Posted: Wed Jul 29, 2009 8:22 pm
by McInfo
VALIDATE_INT should be FILTER_VALIDATE_INT on line 29.

Take the parentheses out of the query on line 62.

Edit: This post was recovered from search engine cache.

Re: Parse error: syntax error, unexpected T_ECHO, expecting

Posted: Wed Jul 29, 2009 11:49 pm
by tobimichigan
Its giving
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Year_Summary.php on line 63
Please what's next?

Re: Parse error: syntax error, unexpected T_ECHO, expecting

Posted: Thu Jul 30, 2009 12:18 am
by McInfo
Sorry about my previous suggestion of removing the parentheses from the query.

I think the query is supposed to be

Code: Select all

SELECT COUNT(*) FROM yearly_reports
What is the reason for using an if and a do-while rather than just a while loop?

Code: Select all

if($row = mysql_fetch_array($result)){
    do{
        // Omitted lines
    } while($row = mysql_fetch_array($result));
}
Read this post with an example of pagination: 537019

Edit: This post was recovered from search engine cache.

Re: Parse error: syntax error, unexpected T_ECHO, expecting

Posted: Thu Jul 30, 2009 8:00 am
by tobimichigan
McInfo wrote:Sorry about my previous suggestion of removing the parentheses from the query.

I think the query is supposed to be

Code: Select all

SELECT COUNT(*) FROM yearly_reports
What is the reason for using an if and a do-while rather than just a while loop?

Code: Select all

if($row = mysql_fetch_array($result)){
&nbsp; &nbsp; do{
&nbsp; &nbsp; &nbsp; &nbsp; // Omitted lines
&nbsp; &nbsp; } while($row = mysql_fetch_array($result));
}
Read this post with an example of pagination: 537019
Chief McInfo, splendid work. The code is now perfect.