警告:mysql_fetch_assoc():提供的参数不是有效的MySQL结果

时间:2013-11-19 06:20:10

标签: php mysql

更新时,我想在尝试执行此操作时从另一个表格中选择路线的值,显示Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result

这是我的代码:

<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'xxxxxxx';
$dbPassword = 'xxxxxxxxxx';
$dbDatabase = 'fms';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");

$client_id=$_POST['clientid'];
$feild=$_POST['field'];
        $data= $_POST['value'];
        $rownum=$_POST['rowid'];  
        $sql="UPDATE $client_id SET ".$feild." = '".$data."' WHERE net_id = ".$rownum."";

         print $sql;

        mysql_query($sql);  


//Select route from client Table

$sql_select="select route from $client_id WHERE net_id = ".$rownum."";
mysql_query($sql_select);
 print $sql_select;
 print mysql_error();
$i=1;
while($rows=mysql_fetch_assoc($sql_select))
{

    $route=$rows['route'];

}

?>

请帮助我,提前谢谢

2 个答案:

答案 0 :(得分:1)

这样写:

$sql_select="select route from $client_id WHERE net_id = ".$rownum."";
$queryRes = mysql_query($sql_select);
 print $sql_select;
 print mysql_error();
$i=1;
while($rows=mysql_fetch_assoc($queryRes))

您需要将mysql_query()函数返回的#Resource提供给mysql_fetch_assoc()

注意:PHP5.3不推荐使用Mysql_ *。因此应该避免。

答案 1 :(得分:1)

试试这个

$sql_select="select route from $client_id WHERE net_id = ".$rownum."";
$result = mysql_query($sql_select);
 print $result;
 print mysql_error();
$i=1;
while($rows=mysql_fetch_assoc($result))
{

    $route=$rows['route'];

}