<?
  function counter() {
    $conn=mysql_connect("localhost","phpbook","");
    $sql="select *from counter";
    $result=mysql_query($sql);
    $objResult=mysql_fetch_object($result);
    $count=$objResult->counter;
    $sql="update counter set counter=".($count+1)." where id= 1";
    mysql_query($sql,$conn);
    return $count+1;
    }    echo counter();
?>看清楚了!
有区别。

解决方案 »

  1.   

    连接后选数据库:mysql_select_db($dbName); 
      

  2.   

    $sql="select *from counter";
        ----------------->>>>>  $sql="select * from counter";
      

  3.   

    qxm_china(xiaoming)说的对,可能是你的SQL语句错了,你改下试试不行再说!
      

  4.   

    其他的错误先不说,你肯定少了下面一句($dbase代表counter表所在的数据库):
    @mysql_select_db($dbase,$conn) or die ("Unable to select database");
    可以加在"$conn=mysql_connect("localhost","phpbook","");"这行的后面
      

  5.   

    qxm_china(xiaoming),说的问题我早已经改正了,可是提示还是错误的!
      

  6.   

    我试了上述的方法可是都不能解决问题,还是出现上次的提示,Warning: Supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\mysqlcount.php3 on 
    line 7

      

  7.   

    加个单引号试试看。。你的字段是数字型的吗。。反正mysql不管什么类型加单引号肯定没错
    $sql="update counter set counter='".($count+1)."' where id= '1'";
      

  8.   

    mysql_fetch_object返回的是对象。php是大小写敏感的,所以再看看你的counter字段到底是counter 还是Counter还是COUNTER还是cCounter
    (哇,怎么这么罗嗦)
      

  9.   

    我是按照上述的方法做了,可是还没有解决错误提示是Warning: Supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\mysqlcount.php3 on 
    line 7

    <?
       function counter() {
        $conn=mysql_connect("localhost","phpbook","");
        @mysql_select_db($dbName);
        $sql="select * from counter";
        $result=mysql_query($sql);
        $objResult=mysql_fetch_array($result);
        $count=$objResult->counter;
        $sql="update counter set counter=".($count+1)." where id= 1";
        mysql_query($sql,$conn);
        return $count+1;
        }    echo counter();
    ?>
      

  10.   

    $dbName---改为你自己的数据库名