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

后端 未结 30 2780
鱼传尺愫
鱼传尺愫 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条回答
  •  Happy的楠姐
    2020-11-21 07:13

    There might be two reasons:

    1. Have you opened the connection to the database prior to calling mysql_query function? I don't see that in your code. Use mysql_connect before making the query. See php.net/manual/en/function.mysql-connect.php

    2. The variable $username is used inside a single quote string, so its value will not be evaluated inside the query. The query will definitely fail.

    Thirdly, the structure of query is prone to SQL injection. You may use prepared statements to avoid this security threat.

提交回复
热议问题