Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do i have to click twice?
    primarykey
    data
    text
    <p>I have a login page where i have to : insert user and password (1 time); click the button(the login button) twice to actually login.I use Xamp with PHP 5.3 and HeidiSQL .If i'm already in session, it skips the login window and redirects to content page else the form is submitted(which is what i want it to do).This is my code :</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;?php session_start(); include("../conect.php"); if(isset($_SESSION['name'])) { $username = $_SESSION['name']; $pass = $_SESSION['pass']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info[2]){ header('.&lt;?php $_PHP_SELF ?&gt;.'); } else { if($_SESSION['role']==0) header("Location: content0.php"); if($_SESSION['role']==1) header("Location: content1.php"); if($_SESSION['role']==2) header("Location: content2.php"); } } } //if the login form is submitted if (isset($_POST['login'])) { $nume=mysql_real_escape_string($_POST['username']); $parola=md5(mysql_real_escape_string($_POST['pass'])); if((!$_POST['username']) || (!$_POST['pass'])) { die('You did not fill in a required field.'); } $check_pass = mysql_query("SELECT * FROM users WHERE username = '$nume'")or die(mysql_error()); $check2 = mysql_num_rows($check_pass); if ($check2 == 0) { die("That user does not exist in our database"); } while($data = mysql_fetch_array( $check_pass )) { //gives error if the password is wrong if ($parola != $data[2]) { die('Incorrect password, please try again.'); } else { $result = mysql_query("SELECT * FROM users WHERE username = '$nume'")or die(mysql_error()); while($data=mysql_fetch_row($result)){ $_SESSION['name']=$data[1]; $_SESSION['pass']=$data[2]; $_SESSION['role']=$data[3]; } } } } mysql_close($con); ?&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Login&lt;/title&gt; &lt;link rel="stylesheet" href="/css/butoane.css" type="text/css" /&gt; &lt;link rel="stylesheet" href="/css/admin_tools.css" type="text/css" /&gt; &lt;script&gt; &lt;/script&gt; &lt;/head&gt; &lt;body id="login_background"&gt; &lt;div id="ambele"&gt; &lt;div class="form_box"&gt; &lt;form action="&lt;?php $_PHP_SELF ?&gt;" method="post"&gt; &lt;label for="username"&gt;Username&lt;/label&gt;&lt;input type="text" id="username" name="username" maxlength="40"/&gt; &lt;label for="password"&gt;Password&lt;/label&gt;&lt;input type="password" id="password"name="pass" maxlength="20"/&gt; &lt;input type="submit" name ="login" value="Login" class="button"/&gt; &lt;/form&gt; &lt;/div&gt; &lt;div id="register"&gt; &lt;a href="registration_form.php" id="reg"&gt;Not registered yet? Go to Registration&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    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