Note that there are some explanatory texts on larger screens.

plurals
  1. POCounting rows with conditions?
    primarykey
    data
    text
    <p>Before you say it has been answered before, I have tried everything, literally.</p> <p>I am trying to count the number of rows in a mysqli query with two WHERE clauses.</p> <pre><code>if (isset($_POST['member_name']) and isset($_POST['memeber_password'])) { $member_name_input = mysqli_real_escape_string($query, $_POST['member_name']); $member_password_input = mysqli_real_escape_string($query, $_POST['member_password']); $result = mysqli_query($query, "SELECT count(*) AS member_count FROM `members` WHERE `member_name` = '$member_name_input' AND `member_password` = '$member_password_input'") or die(mysqli_error($query)); $counter = $row['member_count']; if ($counter = 1) { $result = mysqli_query($query, "SELECT * FROM `members` WHERE `member_name`='$member_name_input' AND `member_password`='$member_password_input'") or die(mysqli_error($query)); $row = mysqli_fetch_array($result); $member_suspended = $row['member_suspended']; $member_validation = $row['member_validation']; } if ($member_suspended &lt; time() and $member_validation = 2) { $_SESSION['member_id'] = $row['member_id']; echo $counter; } elseif ($member_suspended &gt;= time()) { $suspension_date = date('d. m. y.', $member_suspended); echo '&lt;div class="left_container"&gt;&lt;h3&gt;You are suspended until '.$suspension_date.'.&lt;/h3&gt;&lt;/div&gt;'; } elseif ($member_validation = 1) { echo '&lt;div class="left_container"&gt;&lt;h3&gt;Your account has not been confirmed, yet.&lt;/h3&gt;&lt;/div&gt;'; } else { echo '&lt;div class="left_container"&gt;&lt;h3&gt;Login unsuccessful.&lt;/h3&gt;&lt;/div&gt;'; } } </code></pre> <p>My problem is that when I try logging in with an invalid password and/or username (the combination doesn't exists in the table), $counter is still 1 and it fulfills the requirements for the first if statement.</p> <p>I have tried counting the rows in many ways, none of which worked.</p> <p>Some of the other attempts were:</p> <pre><code>$counter = 0; while ($row = mysqli_fetch_array($result)) { ++$counter; } </code></pre> <p>and</p> <pre><code>$counter = mysqli_num_rows($result); </code></pre> <p>I'm just trying to come up with a way to log my users in successfully, and show error messages to invalid login attempts.</p> <p>Thank you for taking your time to read through this and try to help. :)</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.
    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