Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
    primarykey
    data
    text
    <p>I am trying to select data from a MySQL table, but I get one of the following error messages:</p> <blockquote> <p>mysql_fetch_array() expects parameter 1 to be resource, boolean given</p> </blockquote> <p>or</p> <blockquote> <p>mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given</p> </blockquote> <p>or</p> <blockquote> <p>Call to a member function fetch_array() on boolean / non-object</p> </blockquote> <p>This is my code:</p> <pre><code>$username = $_POST['username']; $password = $_POST['password']; $result = mysql_query('SELECT * FROM Users WHERE UserName LIKE $username'); while($row = mysql_fetch_array($result)) { echo $row['FirstName']; } </code></pre> <p>The same applies to code like </p> <pre><code>$result = mysqli_query($mysqli, 'SELECT ...'); // mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given while( $row=mysqli_fetch_array($result) ) { ... </code></pre> <p>and</p> <pre><code>$result = $mysqli-&gt;query($mysqli, 'SELECT ...'); // Call to a member function fetch_assoc() on a non-object while( $row=$result-&gt;fetch_assoc($result) ) { ... </code></pre> <p>and </p> <pre><code>$result = $pdo-&gt;query('SELECT ...', PDO::FETCH_ASSOC); // Invalid argument supplied for foreach() foreach( $result as $row ) { ... </code></pre> <p>and </p> <pre><code>$stmt = $mysqli-&gt;prepare('SELECT ...'); // Call to a member function bind_param() on a non-object $stmt-&gt;bind_param(...); </code></pre> <p>and</p> <pre><code>$stmt = $pdo-&gt;prepare('SELECT ...'); // Call to a member function bindParam() on a non-object $stmt-&gt;bindParam(...); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload