Note that there are some explanatory texts on larger screens.

plurals
  1. POSelecting from a PDO object with fetchAll()
    primarykey
    data
    text
    <p>For some reason the following code always returns true, no matter what the parameter is and what is actually inside of the SQL row. It also throws an error "Notice: Undefined offset: 0 in C:\wamp\www\Social Networking\INC\login.inc on line 7" but I do not see what is wrong:</p> <pre><code>&lt;?php function checkAccount($username, $password){ include("INC/dbconnect.inc");/*"INC/dbconnect.inc" is &lt;?php $pdo = new PDO("mysql:host=localhost;dbname=socialnetwork","user","123"); ?&gt;*/ $select = $pdo-&gt;prepare("SELECT id,password FROM users WHERE user_username = :username"); $select-&gt;execute(array(':username'=&gt;$username)); $q_rows = $select-&gt;fetchAll(); if($q_rows[0][0]/*the ID of the user, it should always be greater than 1, if not then the username does not exist*/ &gt; 0 &amp;&amp; $q_rows[0][0] != null){ if($q_rows[0][1]/*the password of the user*/ == $password) return true; else return false; } else return false; $pdo=null; } ?&gt; </code></pre> <p>Can someone please tell me what is wrong? I have commented inside of the code the problems I am experiencing, and I have tried normal <code>$select-&gt;fetch()</code> instead of <code>$select-&gt;fetchAll()</code> to no avail. I have read up on PDO before posting this (<a href="http://php.net/manual/en/pdostatement.fetchall.php" rel="nofollow">http://php.net/manual/en/pdostatement.fetchall.php</a>). Here is the rest of my file <a href="http://pastebin.com/YCkrRivs" rel="nofollow">http://pastebin.com/YCkrRivs</a>, thanks. </p>
    singulars
    1. This table or related slice is empty.
    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.
    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