<?php
$mysql_db = mysql_connect("localhost","root","root");
@mysql_select_db("test",$mysql_db);
$result = mysql_query("select * from user where name = '张三'");
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
    echo  $row['name'];
}
?>
提示错误如下:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\www\test\user01.php on line 13

解决方案 »

  1.   

    你的sql语句中张三这个字符串,用得是中文下的单引号吧。所以提示is not a valid MySQL
      

  2.   

    sql语句中张三这个字符串,用得是英文下的单引号
      

  3.   

    或者你把sql语句粘到phpadmin里,看一下执行结果
      

  4.   

    sql语句我在phpmyadmin中试过了没有问题
    表中数据如下:
     id  name  tel          educational  date  
     5   张四   020-5566556  中专毕业       2006-10-15 
     3   张三   13612312331  本科毕业       2006-10-15 
     1   张三   13333663366  大专毕业       2006-10-11 
     4   王五   13521212125  大专毕业       2006-12-25 
      

  5.   

    把 mysql_select_db前的@  去掉,看报错信息。
      

  6.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <?php
    $mysql_db = mysql_connect("localhost","root","root");
    mysql_select_db("test",$mysql_db);
    $result = mysql_query("select * from user where name = '张三'");
    while($row = mysql_fetch_array($result,MYSQL_ASSOC))
    {
          echo $row['id'].''.$row['name'];
    }
    ?>
    </body>
    </html>去掉了以后报错如下:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\www\test\user01.php on line 13
      

  7.   


    <?php 
    $mysql_db = mysql_connect("localhost","root","root"); 
    mysql_select_db("test",$mysql_db); 
    mysql_query("set names 'gbk'"); //增加这个代码试试看,可能是编码问题导致你查询不到结果
    $result = mysql_query("select * from user where name = '张三'"); 
    while($row = mysql_fetch_array($result,MYSQL_ASSOC)) 

          echo $row['id'].''.$row['name']; 

    ?> 
      

  8.   

    当然前提是你数据库编码是gbk哦。。
      

  9.   

    这个报错是PHP的报错,你要看mysql数据库的错误信息是什么。mysql_query("...") or die(mysql_error());