mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource

后端 未结 30 3269
鱼传尺愫
鱼传尺愫 2020-11-21 06:25

I am trying to select data from a MySQL table, but I get one of the following error messages:

mysql_fetch_array() expects parameter 1 to be resource,

30条回答
  •  孤城傲影
    2020-11-21 07:19

    You can also check wether $result is failing like so, before executing the fetch array

    $username = $_POST['username'];
    $password = $_POST['password'];
    $result = mysql_query('SELECT * FROM Users WHERE UserName LIKE $username');
    if(!$result)
    {
         echo "error executing query: "+mysql_error(); 
    }else{
           while($row = mysql_fetch_array($result))
           {
             echo $row['FirstName'];
           }
    }
    

提交回复
热议问题