一直出现Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in d:\appserv

edited 十月 2013 in PHP新手區
<?

//
[ 膀セ砞﹚ ]
$mysql_server_name = "localhost";
$mysql_username = "";
$mysql_password = "";
$mysql_database = "";
//

echo $ip=getenv('REMOTE_ADDR');

//SELECT
//建立连线
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );

//准备你的CQL语法
$sql = "SELECT * FROM `sky`WHERE ip='$ip'AND name= 'cool3'";

//进行查询
$result=mysql_db_query( $mysql_database, $sql,$conn );

//将查询的结果--》抓出
$row=mysql_fetch_row($result);

//印出该资料的所有地址[阵列]
print_r($row);

//清楚查询结果
mysql_free_result($result);


if(!$row)
{

//建立连线
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password);



//准备好你的SQL语法
$sql = "INSERT INTO `sky` ( `name` , `aaa` , `ip` , `time_at` )VALUES ('cool3', '1', '$ip', NOW( ) )";

//选取你要处理的资料库
mysql_select_db($mysql_database,$conn);

//进行查询
$result = mysql_query($sql);

//结束并释放连线
mysql_close($conn);
}
else
{
//建立连线
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );

//准备你的CQL语法
$sql = "SELECT TIME_TO_SEC( NOW( ) ) - TIME_TO_SEC( time_at )FROM `sky`WHERE ip = '$ip' AND name = 'cool3'ORDER BY `TIME_TO_SEC( NOW( ) )- TIME_TO_SEC( time_at )` ASC ";

//进行查询
$result=mysql_db_query( $mysql_database, $sql,$conn );

//将查询的结果--》抓出
$row=mysql_fetch_row($result);

//印出该资料的所有地址[阵列]
print_r($row);

//清楚查询结果
mysql_free_result($result);


/*
if()
{
//建立连线
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password);



//准备好你的SQL语法
$sql = "INSERT INTO `sky` ( `name` , `aaa` , `ip` , `time_at` )VALUES ('cool3', '1', '$ip', NOW( ) )";

//选取你要处理的资料库
mysql_select_db($mysql_database,$conn);

//进行查询
$result = mysql_query($sql);

//结束并释放连线
mysql_close($conn);
}
*/

}




//
//建立连线
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password);



//准备好你的SQL语法
$sql = "INSERT INTO `sky` ( `name` , `aaa` , `ip` , `time_at` )VALUES ('cool3', '1', '$ip', NOW( ) )";

//选取你要处理的资料库
mysql_select_db($mysql_database,$conn);

//进行查询
$result = mysql_query($sql);

//结束并释放连线
mysql_close($conn);



//

//建立连线
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );

//准备你的CQL语法
$sql = "SELECT COUNT( * ) FROM `sky` WHERE name= 'cool3'";

//进行查询
$result=mysql_db_query( $mysql_database, $sql,$conn );

//将查询的结果--》抓出
$row=mysql_fetch_row($result);

//印出该资料的所有地址[阵列]
//print_r($row);

//清楚查询结果
mysql_free_result($result);

//
//建立连线
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );

//准备你的CQL语法
$sql = "SELECT COUNT( * ) FROM `sky` WHERE name= 'cool2'";

//进行查询
$result=mysql_db_query( $mysql_database, $sql,$conn );

//将查询的结果--》抓出
$aaa=mysql_fetch_row($result);

//印出该资料的所有地址[阵列]
//print_r($row);

//清楚查询结果
mysql_free_result($result);



?>
因为网页报出:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in d:\appserv\www\ip.php on line 64

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in d:\appserv\www\ip.php on line 70

请帮帮忙

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=2125

評論

  • edited 九月 2006
    58行的
    $sql = "SELECT TIME_TO_SEC( NOW( ) ) - TIME_TO_SEC( time_at )FROM `sky`WHERE ip = '$ip' AND name = 'cool3'ORDER BY `TIME_TO_SEC( NOW( ) )- TIME_TO_SEC( time_at )` ASC ";

    這一段有問題,從這解決吧
  • edited 九月 2006
    58行的
    $sql = "SELECT TIME_TO_SEC( NOW( ) ) - TIME_TO_SEC( time_at )FROM `sky`WHERE ip = '$ip' AND name = 'cool3'ORDER BY `TIME_TO_SEC( NOW( ) )- TIME_TO_SEC( time_at )` ASC ";
    我试了几次还是出现
    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in d:\appserv\www\ip.php on line 64

    Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in d:\appserv\www\ip.php on line 70

    不知道错的哪里,请帮忙看出错在哪里
    谢谢了
  • edited 九月 2006
    很期待能解决这个问题,因为这个问题不解决后面的也都出现了问题,都说是$row=mysql_fetch_row($result);
    mysql_free_result($result);
    这两个有问题
  • edited 九月 2006
    你可以嘗試在mysql中直接執行看看顯示的結果
    或用php把mysql的error message show出來

    mysql語法錯誤只有自己的環境才能測試,沒那環境是”看”不出錯誤的
  • edited 九月 2006
    把58行的
    $sql = "SELECT TIME_TO_SEC( NOW( ) ) - TIME_TO_SEC( time_at )FROM `sky`WHERE ip = '$ip' AND name = 'cool3'ORDER BY `TIME_TO_SEC( NOW( ) )- TIME_TO_SEC( time_at )` ASC ";
    这个在MYSQL中执行后就出现
    #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '$sql = "SELECT TIME_TO_SEC( NOW( ) ) - TIME_TO_SEC( time_at )F

    但是$sql = "SELECT TIME_TO_SEC( NOW( ) ) - TIME_TO_SEC( time_at )FROM `sky`WHERE ip = '$ip' AND name = 'cool3'
    MYSQL中执行是正确的

    其实这个语法我也是在MYSQL中由上面执行正确后在复制的
    $sql = "SELECT TIME_TO_SEC( NOW( ) ) - TIME_TO_SEC( time_at )FROM `sky`WHERE ip = '$ip' AND name = 'cool3'ORDER BY `TIME_TO_SEC( NOW( ) )- TIME_TO_SEC( time_at )` ASC ";
  • edited 九月 2006
    FROM 跟前面的欄位名稱沒有空格?
    'cool3'ORDER 也沒有適當的空格?
  • edited 九月 2006
    改了,还是老样子
    一样的错误
    是不是版本的问题还是其他问题呢

    真是麻烦你了
  • edited 九月 2006
    我安装的是appserv-win32-2.4.0.exe
    系统是XP的

    在运行http://127.0.0.1/phpnuke/html
    也出现很多错误
    别人的机子上运行都是正常的
  • edited 九月 2006
    我今天终于知道错在哪里了
    反正还是先谢谢上面那些朋友给我指导啦
    $sql = "SELECT TIME_TO_SEC( NOW( ) ) - TIME_TO_SEC( time_at )FROM `sky`WHERE ip = '$ip' AND name = 'cool3'ORDER BY `TIME_TO_SEC( NOW( ) )- TIME_TO_SEC( time_at )` ASC ";

    `TIME_TO_SEC( NOW( ) )- TIME_TO_SEC( time_at )`不该要引号
Sign In or Register to comment.