Forum Moderators: coopster

Message Too Old, No Replies

unexpected $

         

bodycount

4:41 pm on Nov 8, 2005 (gmt 0)

10+ Year Member



I am getting the following error on my page

"Parse error: parse error, unexpected $ in /home/body2985/public_html/numberofrecords.php on line 123"

I have had a look at my code and there is no line 123, NOTE I am a noobie , what have I done wrong?

<?
include ("connection.php");
//$db_addr = 'localhost';// address of MySQL server.
//$db_user = 'user';// Username to access server.
//$db_pass = 'password';// Password access server.
//$db_name = 'MyDatabase';// Name of database to connect to.
//$connect = @mysql_connect("$db_addr", "$db_user", "$db_pass");

//if (!($connect)) // If no connect, error and exit().
//{
//echo("<p>Unable to connect to the database server.</p>");
//exit();
//}

//if (!(@mysql_select_db($db_name))) // If can't connect to database, error and exit().
//{
//echo("<p>Unable to locate the $db_name database.</p>");
//exit();
//}

if (!($limit)){
$limit = 10;} // Default results per-page.
if (!($page)){
$page = 0;} // Default page value.
$numresults = mysql_query("SELECT * FROM ADDRESSES WHERE ID LIKE '%". $query ."%'"); // the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
if ($numrows == 0){
echo("No results found matching your query - $query"); // bah, modify the "Not Found" error for your needs.
exit();}

$pages = intval($numrows/$limit); // Number of results pages.

// $pages now contains int of pages, unless there is a remainder from division.

if ($numrows%$limit) {
$pages++;} // has remainder so add one page

$current = ($page/$limit) + 1; // Current page number.

if (($pages < 1) ¦¦ ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.

else {
$total = $pages;} // Else total pages is $pages value.

$first = $page + 1; // The first result.

if (!((($page + $limit) / $limit) >= $pages) && $pages!= 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.

else{
$last = $numrows;} // If last results page, last result equals total number of results.

//escape from PHP mode.
?>
<html>
<head>
<title>Search Results for <?=$query?></title>
</head>
<body>
<center><h2>Search Results for <?=$query?></h2></center>
<table width="100%" border="0">
<tr>
<td width="50%" align="left">
Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>
</td>
<td width="50%" align="right">
Page <b><?=$current?></b> of <b><?=$total?></b>
</td>
</tr>
<tr>
<td colspan="2" align="right">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2" align="right">
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> ¦ <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a> ¦ <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a> ¦ <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a>
</td>
</tr>
</table>
<?
//Go back into PHP mode.

// Now we can display results.
$results = mysql_query("SELECT `ID`, `FULLNAME`, `YOB`, `PLACEBIRTH`, `MARRIED_NAME` FROM ADDRESSES WHERE ID LIKE '%". $query ."%' ORDER BY `ID` LIMIT $page, $limit");
//$results = mysql_query("SELECT * FROM ADDRESSES WHERE FULLNAME LIKE '%". $query ."%' ORDER BY FULLNAME ASC LIMIT $page, $limit");
echo "<table align=\"center\" border=\"8\">";
echo "<tr><th>ID</th><th>Birth Name</th><th>Married Name</th><th>Date/Year of Brith</th><th>Place of Birth</th>";
while ($row = mysql_fetch_array($results))
{
$ID = $row['ID'];
$FULLNAME = $row['FULLNAME'];
$MARRIED_NAME = $row['MARRIED_NAME'];
$YOB = $row['YOB'];
$PLACEBIRTH = $row['PLACEBIRTH'];
echo "<tr><td><a href=\"pre_change.php?row_ID=$ID\">$ID</a></td><td>$FULLNAME</td><td>$MARRIED_NAME</td><td>$YOB</TD><TD>$PLACEBIRTH</TD></TR>";
//<p><a href="<?=$data["ID"]?>" title="<?=$data["ID"]?>"><?=$data["FULLNAME"]?></a> - <?=$data["YOB"]?></p>
}
?>
<p align="center">
<?
if ($page!= 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a> \n");}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b> \n");} // If current page don't give link, just text.
else{
echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages!= 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>\n");}
?>
</p>
</body>
</html>

gsnider

4:43 pm on Nov 8, 2005 (gmt 0)

10+ Year Member



it counts the lines in your connection.php as well...

bodycount

4:58 pm on Nov 8, 2005 (gmt 0)

10+ Year Member



I have had a look in the connection.php and the is 22 lines in there including Spaces between lines.

So does that mean that the problem line is "$ppage = $limit*($i - 1);"

jatar_k

5:02 pm on Nov 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I actually don't think it includes the count from any included files, at least I can't ever remember having that issue

when you get an error that represents the last line (or the line after for that matter) it is often mismatched braces. I don't see any in your code, they all seem to match. Though I had to reformat a bunch to find them all.

what did you change right before you got this error?

jatar_k

5:05 pm on Nov 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I compressed inline ifs and removed the comments at the top and am working off of this

<?
include ("connection.php");
if (!($limit)) $limit = 10; // Default results per-page.
if (!($page)) $page = 0; // Default page value.
$numresults = mysql_query("SELECT * FROM ADDRESSES WHERE ID LIKE '%". $query ."%'"); // the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
if ($numrows == 0) {
echo("No results found matching your query - $query"); // bah, modify the "Not Found" error for your needs.
exit();
}
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows%$limit) $pages++; // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) ¦¦ ($pages == 0)) $total = 1; // If $pages is less than one or equal to 0, total pages is 1.
else $total = $pages; // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages!= 1) $last = $page + $limit; //If not last results page, last result equals $page plus $limit.
else $last = $numrows; // If last results page, last result equals total number of results.
//escape from PHP mode.
?>
<html>
<head>
<title>Search Results for <?=$query?></title>
</head>
<body>
<center><h2>Search Results for <?=$query?></h2></center>
<table width="100%" border="0">
<tr>
<td width="50%" align="left">Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b></td>
<td width="50%" align="right">Page <b><?=$current?></b> of <b><?=$total?></b></td>
</tr>
<tr>
<td colspan="2" align="right">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="right">Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> ¦ <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a> ¦ <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a> ¦ <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a></td>
</tr>
</table>
<?
//Go back into PHP mode.
// Now we can display results.
$results = mysql_query("SELECT `ID`, `FULLNAME`, `YOB`, `PLACEBIRTH`, `MARRIED_NAME` FROM ADDRESSES WHERE ID LIKE '%". $query ."%' ORDER BY `ID` LIMIT $page, $limit");
//$results = mysql_query("SELECT * FROM ADDRESSES WHERE FULLNAME LIKE '%". $query ."%' ORDER BY FULLNAME ASC LIMIT $page, $limit");
echo "<table align=\"center\" border=\"8\">";
echo "<tr><th>ID</th><th>Birth Name</th><th>Married Name</th><th>Date/Year of Brith</th><th>Place of Birth</th>";
while ($row = mysql_fetch_array($results)) {
$ID = $row['ID'];
$FULLNAME = $row['FULLNAME'];
$MARRIED_NAME = $row['MARRIED_NAME'];
$YOB = $row['YOB'];
$PLACEBIRTH = $row['PLACEBIRTH'];
echo "<tr><td><a href=\"pre_change.php?row_ID=$ID\">$ID</a></td><td>$FULLNAME</td><td>$MARRIED_NAME</td><td>$YOB</TD><TD>$PLACEBIRTH</TD></TR>";
//<p><a href="<?=$data["ID"]?>" title="<?=$data["ID"]?>"><?=$data["FULLNAME"]?></a> - <?=$data["YOB"]?></p>
}
?>
<p align="center">
<?
if ($page!= 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a> \n");
}
for ($i=1; $i <= $pages; $i++) {// loop through each page and give link to it.
$ppage = $limit*($i - 1);
if ($ppage == $page) echo("<b>$i</b> \n"); // If current page don't give link, just text.
else echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");
}
if (!((($page+$limit) / $limit) >= $pages) && $pages!= 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>\n");
}
?>
</p>
</body>
</html>

bodycount

9:35 pm on Nov 8, 2005 (gmt 0)

10+ Year Member



OK this is the code before editing

<?
include ("connection.php");
/*<?
$db_addr = 'localhost';// address of MySQL server.
$db_user = 'user';// Username to access server.
$db_pass = 'password';// Password access server.
$db_name = 'MyDatabase';// Name of database to connect to.
$connect = @mysql_connect("$db_addr", "$db_user", "$db_pass");

if (!($connect)) // If no connect, error and exit().
{
echo("<p>Unable to connect to the database server.</p>");
exit();
}

if (!(@mysql_select_db($db_name))) // If can't connect to database, error and exit().
{
echo("<p>Unable to locate the $db_name database.</p>");
exit();
}
*/
if (!($limit)){
$limit = 10;} // Default results per-page.
if (!($page)){
$page = 0;} // Default page value.
$numresults = mysql_query("SELECT * FROM ADDRESSES WHERE FULLNAME LIKE '%". $query ."%'"); // the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
if ($numrows == 0){
echo("No results found matching your query - $query"); // bah, modify the "Not Found" error for your needs.
exit();}

$pages = intval($numrows/$limit); // Number of results pages.

// $pages now contains int of pages, unless there is a remainder from division.

if ($numrows%$limit) {
$pages++;} // has remainder so add one page

$current = ($page/$limit) + 1; // Current page number.

if (($pages < 1) ¦¦ ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.

else {
$total = $pages;} // Else total pages is $pages value.

$first = $page + 1; // The first result.

if (!((($page + $limit) / $limit) >= $pages) && $pages!= 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.

else{
$last = $numrows;} // If last results page, last result equals total number of results.

//escape from PHP mode.
?>
<html>
<head>
<title>Search Results for <?=$query?></title>
</head>
<body>
<center><h2>Search Results for <?=$query?></h2></center>
<table width="100%" border="0">
<tr>
<td width="50%" align="left">
Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>
</td>
<td width="50%" align="right">
Page <b><?=$current?></b> of <b><?=$total?></b>
</td>
</tr>
<tr>
<td colspan="2" align="right">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2" align="right">
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> ¦ <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a> ¦ <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a> ¦ <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a>
</td>
</tr>
</table>
<?
//Go back into PHP mode.

// Now we can display results.
$results = mysql_query("SELECT * FROM ADDRESSES WHERE FULLNAME LIKE '%". $query ."%' ORDER BY FULLNAME ASC LIMIT $page, $limit");
while ($data = mysql_fetch_array($results))
{
?>
<p><a href="<?=$data["ID"]?>" title="<?=$data["FULLNAME"]?>"><?=$data["FULLNAME"]?></a> - <?=$data["YOB"]?></p>
<?
}
?>
<p align="center">
<?
if ($page!= 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a> \n");}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b> \n");} // If current page don't give link, just text.
else{
echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages!= 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>\n");}
?>
</p>
</body>
</html>

bodycount

10:03 pm on Nov 8, 2005 (gmt 0)

10+ Year Member



I have got it to work, I think the error was ME, I was being too trigger happy. If you want me to post the finished code I will.

jatar_k

10:04 pm on Nov 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



glad you got it sorted

<added>I keep looking at this title and laughing

>> unexpected $

I could really use some unexpected money

;)

[edited by: jatar_k at 10:48 pm (utc) on Nov. 8, 2005]

bodycount

10:44 pm on Nov 8, 2005 (gmt 0)

10+ Year Member



lol