首 页   · 站长博客 · 用户注册 · 会员登陆  · 会员排行  ·最新主题  ·最近回复  精华区  版权声明  ·论坛管理
  当前登录身份:游客,请先登录。  笔名: 口令: 验证码:   
楼 主  index »  PHP+MYSQL编程 » [原创]“Parse error: parse error, unexpected $ ”请问,到底是哪里出了问..  


  作者:tkh321
  注册时间:2005-05-17
  主题/回复:1/1
  积分:406
  等级:★★☆(五级)
  称号:略有小成

  whn231@163.com
  未提供
  www.

 

 发表:2005-05-17 02:06:01 阅读 2363 次 回复 2 次 得分1  |   字号 字色
[原创]“Parse error: parse error, unexpected $ ”请问,到底是哪里出了问题呢?
聂老师,这是一段 实现“查询搜索”的代码;程序运行时,不知道为什么,总是出现如下错误:

Parse error: parse error, unexpected $ in /var/www/html/tsg/search_book.php on line 224

也就是提示说,问题出在 第224行,可是我的这段代码,总共才223行
我也找过这个问题的解决方法,有的说是 “{“ 没有成对匹配,可我找了很久,都没找出来。


请问,到底是哪里出了问题呢?
代码如下:

**************************************************************

<?php
include("db_connect.php"); 
//进行数据库连接
$conn=@mysql_connect($db_server,$db_user_name,$db_user_password);
if(! $conn)
{
echo "<P align=center>数据库连接出错";
exit(0);
}
$flag=@mysql_select_db($db_name,$conn);
if(! $flag)
{
echo "<P align=center>选择数据库出错";
exit(0);
}
if($mode==""):
?>
//产生书籍查询页面
<p> </p>
<div align="center">
<center>
<table border="1" width="60%" bordercolor="#008000" 
cellspacing="0" cellpadding="0" height="277">
<tr>
<td width="100%" height="275" valign="top">
<p align="center" class="1">书籍查询</P>
<form action="search_book.php?mode=doit" method="post">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="right">书名:</td>
<td width="50%"><input type="text" name="book_title" size="20"></td>
</tr>
<tr>
    <td width="50%" align="right">作者:</td>
    <td width="50%">
<input type="text" name="member_name" size="20"></td>
</tr>
<tr>
<td width="50%" align="right">出版社:</td>
    <td width="50%"><input type="text" name="publish" size="20"></td>
</tr>
<tr>
    <td width="50%" align="right">出版时间:</td>
    <td width="50%"><input type="text" name="outtime1" size="4">年
<input type="text" name="outtime2" size="2">月</td>
</tr>
<tr>
<td width="50%" align="right">各条件:与
<input type="radio" value="and" name="select1" checked>或
<input type="radio" value="or" name="select1"> </td> 
  <td width="50%">绝对匹配 
<input type="radio" value="yes" name="select2" checked>
模糊匹配<input type="radio" value="no" name="select2"></td> 
</tr> 
<tr> 
<td width="50%" align="center" colspan="2">
<input type="submit" value="查询" name="B1"></td> 
</tr> 
    </table> 
    </form> 
    <p align=center><font color=red size=2>请注意:
输入条件中应至少有一项不为空</font></p>
   </td> 
    </tr> 
  </table> 
  </center> 
</div> 
<?php
endif;

function selects($strname,$strname2,$selectkey,$selectname)
{
global $sql;
if($selectname=="" || $selectname==" ")
;
else
if(strpos($sql,"=") || strpos($sql,"like"))
if($selectkey=="yes")
return " ".$strname2." ".$strname."='".$selectname."'";
else
return " ".$strname2." ".$strname." like '%".$selectname."%'";
else
if($selectkey=="yes")
return $strname."='".$selectname."'";
else
return $strname." like '%".$selectname."%'";

}
if($mode=="doit")
{
//构造查询条件
$postword="search_book.php?mode=doit&book_title=".$book_title."
&member_name=".$member_name;
$postword.="&publish=".$publish."&outtime1=".$outtime1."
&outtime2=".$outtime2."&select1=".$select1."&select2=".$select2;
if($pager=="")
$pagenum=0;
else
$pagenum=$pager;
$pagenum=(int)$pagenum;
$sql="select * from book where (".selects("book_title",$select1,$select2,$book_title);
$sql.=selects("book_author",$select1,$select2,$member_name);
$sql.=selects("book_publishing",$select1,$select2,$publish);
if(trim($outtime1)=="")
$outtimes="";
else
{
if(trim($outtime2)=="")
$temptime="01";
else
$temptime=$outtime2;
echo $temptime."01".$outtime1;
if(checkdate($temptime,"01",$outtime1))
{
$outtimes=$outtime1."-".$temptime."-01";
}
else
$outtimes="";

}
$sql.=") order by book_publishinging_time desc";
$sql.=" limit ".($pagenum*$page_counter).",".(($pagenum+1)*$page_counter);
//进行查询
$rs=@mysql_query($sql,$conn) or die ("<P align=center>查询发生错误<br>
<a href=\"javascript:history.go(-1)\">返回</a>");
if(mysql_num_rows($rs)==0)
echo "<P align=center>数据库中没有符合要求的记录<br>
<a href=\"javascript:history.go(-1)\">返回</a>";
else
list_sequel($rs,$postword,$oldsql);
}
mysql_close($conn);

//显示查询结果
function list_sequel($rs,$postword,$oldsql)
{
global $conn,$page_counter,$pagenum;
?>
<div align="center">
<center>
<table border="1" width="90%" bordercolor="#008000" cellspacing="0" 
cellpadding="0" height="205">
    <tr>
    <td width="100%" height="203" valign="top">
    <p align="center" class="1">查询结果</p>
    <table border="1" width="100%" cellspacing="0" 
cellpadding="0" bordercolor="#FFCCCC">
  <tr>
<td width="20%" align="center" height="21">书名</td>
<td width="10%" align="center">作者</td>
<td width="20%" align="center">出版社</td>
<td width="10%" align="center">出版日期</td>
<td width="24%" align="center">书籍编号</td>
<td width="8%" align="center">总库存</td>
<td width="8%" align="center">现存</td>
    </tr>
<?php
while($lists=mysql_fetch_array($rs))
{
  echo "<tr><td width=\"20%\" height=\"21\">";
  echo $lists[book_title];
  echo "</td>";
  
  echo "<td width=\"10%\">";
  echo $lists[book_author];
  echo "</td>";
  
  echo "<td width=\"20%\">";
  echo $lists[book_publishing];
  echo "</td>";
  echo "<td width=\"10%\">";
  echo substr($lists[book_publishinging_time],0,7);
  echo "</td>";
  
  echo "<td width=\"24%\">";
  echo $lists[book_number];
  echo "</td>";
  
  echo "<td width=\"8%\">";
  echo $lists[book_in_number];
  echo "</td>";
  
  echo "<td width=\"8%\">";
  echo $lists[book_stocks];
  echo "</td>";
  
  echo "</tr>";
}
   echo "</table>";
   //分页显示, 确定每页显示记录的条数
   $rs1=mysql_query($oldsql,$conn);
   $maxnum=mysql_num_rows($rs1);
   if($maxnum >= $page_counter)
$maxpagenum= $maxnum / $page_counter;
   if(($maxnum % $page_counter)!=0)
   $maxpagenum+=1;
   echo "<P >";
   $j=0;
   for($i=0;$i<$maxpagenum;$i++)
   {
    if($pagenum!=$i)
    echo "<a href=\"".$postword."&pager=".$i."\">".($i+1)."</a>";
     else
     echo ($i+1);
     if((($j+1) % 15)==0)
     echo "<br>";
     $j+=1;
    }
   echo "</center>";
 echo "<p align=\"right\" >".($pagenum+1)."/".$maxpagenum.";
?>
  </td>
    </tr>
  </table>
</div>
<?php
}
?>
</ body> 
</html> 

*************************************************************

 
 1#楼  
 
  回复人:一起PHP
  注册时间:2004-02-27
  主题/回复:247/1521
  积分:4649
  等级:★★★★★☆(十一级)
  称号:论坛圣人

   
 1#楼 发表于2005-05-17 02:35:36  评分:1 

真是郁闷,这么长的代码,到了最后才发现错误,早知道就倒着看

错误提示的意思是:语法错误:意外的"$"
从头看到尾,倒数第十一行
echo "<p align=\"right\" >".($pagenum+1)."/".$maxpagenum.";
看出来问题了没有?最后那个双引号莫名其妙。修改成下面:
echo "<p align=\"right\" >".($pagenum+1)."/".$maxpagenum;
或者
echo "<p align=\"right\" >".($pagenum+1)."/".$maxpagenum."";
就搞定。

这个程序其他地方还有没错误不知道。但是这样修改之后起码没有语法错误了。

 2#楼  
 
  回复人:tkh321
  注册时间:2005-05-17
  主题/回复:1/1
  积分:406
  等级:★★☆(五级)
  称号:略有小成

   
 2#楼 发表于2005-05-17 03:53:24  评分:× 

聂老师
按照您说的办法,我把那个 “ 给删掉就可以了
错误解决了!
太谢谢了!  赞啊~~~~~
  页数1/1首页 « 1 » 末页
  发表回复:您还没有登陆,无法发表回复。请先[登陆]

一起PHP技术联盟 主办:一起PHP 联系方式:站长QQ:4304410 QQ群:8423742 20159565 站长博客 E-mail: nqp@nqp.me 执行时间:0.012sec
SimsmaBBS 2008 (v6.0) Developed by 17php.com,Copyright(C)2003-2010 All rights reserved. 副本授权:一起PHP官方专用版