Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple if() not working as expected
    primarykey
    data
    text
    <p>I am sure that I am simply overlooking something, and I spent a few days working on this and cant seem to figure it out.</p> <p>after logging in on the previous page I get the username and password,</p> <pre><code>$username = mysql_escape_string($_POST['adminusername']); $password = mysql_escape_string($_POST['adminpassword']); </code></pre> <p>and then I go to the database to pull the username and password from the database,</p> <pre><code>$sql = "SELECT username, password FROM `weaponsadmin`"; $rows = $db-&gt;query($sql); while ($record = $db-&gt;fetch_array($rows)) { </code></pre> <p>now here is the part that is confusing me, if i have the following, no matter what I use for the username or password, it will NOT allow for me to login,</p> <pre><code>if ( ($record[username]==$username) &amp;&amp; ($record[password]==$adminpassword) ){ $_SESSION['loggedin'] = true; $_SESSION['username'] = $adminusername; header( "Location: admin.php" ) ; } else { header( "Location: index.php?login=error" ) ; } </code></pre> <p>however if I use the following, it will allow me to login in if the username is correct, but it allows for me to input anything for password and it works,</p> <pre><code>$adminusername = $record[username]; $adminpassword = $record[password]; if ( ($adminusername==$username) &amp;&amp; ($adminpassword==$adminpassword) ) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $adminusername; header( "Location: admin.php" ) ; } else { header( "Location: index.php?login=error" ) ; } </code></pre> <p>So in summary for some reason the <code>&amp;&amp;</code> part doesn't seem to work correctly and if somebody could help me with the code and let me know where my code could be improved for better security and how to make this work correctly, 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.
 

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