Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble logging a user in using PHP and PDO
    primarykey
    data
    text
    <p>From the PDO manual:</p> <pre><code>PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object. If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications. </code></pre> <p>I have this code:</p> <pre><code>&lt;?php require 'core.inc.php'; if(isset($_POST['user']) AND isset($_POST['pass'])){ if(!empty($_POST['user']) AND !empty($_POST['pass'])){ $user = $_POST['user']; $pass = $_POST['pass']; require 'connect.inc.php'; $st = $db_pdo-&gt;prepare("SELECT id FROM users WHERE user=? AND pass=?"); $st-&gt;bindParam(1, $user); $st-&gt;bindParam(2, $pass); $st-&gt;execute(); $result = $st-&gt;fetchColumn(); if($st-&gt;rowCount() &gt; 0){ $id_arr = $st-&gt;fetch(); $id = $id_arr[0]; $_SESSION['user_id'] = $id; header('Location: edit.php'); } else { echo 'Username or password incorrect';} } else { echo 'You must fill in all fields.';} } ?&gt; </code></pre> <p>The number of rows returned is always 0, as stated in the manual. No surprise there.</p> <p>1) I want to log a user in and set his $_SESSION id to his user ID from a db.</p> <p>2) I suck so much at PDO it's not even funny, I can't figure out what function to use to log the user in. If the number or rows is always 0, clearly the Username or password incorrect will appear all the time.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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