Note that there are some explanatory texts on larger screens.

plurals
  1. POIncorrect password redirects to incorrect page?
    primarykey
    data
    text
    <p>So I put together a very crude login form using php and a mysql database, and I have it set (or so I think) to redirect back to the login page with a "loginFailed=true&amp;reason=password"". I'm trying to just have it redirect back to the login, and display an incorrect password message, but instead it just redirects to the main index page.</p> <p>What am I doing wrong here? Granted I borrowed heavily from some pre-existing code due to my lack of coding-knowledge, but it did work as intended for a bit before redirecting.</p> <p>Here is the code:</p> <p>passwordcheck.php</p> <pre><code>// Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $password = stripslashes($password); $password = mysql_real_escape_string($password); $sql="SELECT * FROM $tbl_name WHERE password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("password"); header("location:admin.html"); } else { die(header("location:login.html?loginFailed=true&amp;reason=password")); } ?&gt; </code></pre> <p>And here is the password field in the login page:</p> <pre><code>&lt;span class="add-on"&gt;&lt;i class="icon-list-alt"&gt;&lt;/i&gt;&lt;/span&gt; &lt;input type="password" id="inputIcon" class="span4" name='password' id='password' maxlength="50" placeholder="&lt;?php $reasons = array("password" =&gt; "Yo shitbird, wrong password."); if ($_GET["loginFailed"]) echo $reasons[$_GET["reason"]]; ?&gt;" /&gt; &lt;/div&gt; </code></pre>
    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