Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The bits about <code>session_start()</code> and <code>session_destroy()</code> do not influence the POST-variables. As BugFinder pointed out, refreshing the page often re-submits whatever data you've just submitted. That's why the 'you're in'-message is presented again.</p> <p>A way of preventing this behaviour is by redirecting after the submitted data has been processed. You could then set a session variable to keep track of the message you still need to display (or, if the user is logged in or not).</p> <p>Your code would look something like this:</p> <pre><code>&lt;?php session_start(); $root = 'root'; mysql_connect('localhost',$root,'') or die(mysql_error()); mysql_select_db("test_create_database") or die(mysql_error()); $result = mysql_query("SELECT * FROM members"); $row = mysql_fetch_assoc($result); $username=""; $password=""; $id=""; if(isset($_POST["submit"])) { if(isset($_POST["submit"]) &amp;&amp; !empty($_POST["username"]) &amp;&amp; !empty($_POST["password"]) &amp;&amp; !empty($_POST["id"])) { if(isset($_POST["username"]) &amp;&amp; isset($_POST["password"]) &amp;&amp; isset($_POST["id"])) { $username = $row["username"]; $password = $row["password"]; $id = $row["id"]; if($username == "John" &amp;&amp; $password =="1234" &amp;&amp; $id =="1") { //do stuff $_SESSION['message'] = "you're in"; } else { $_SESSION['message'] = "you're out!"; } } } elseif (isset($_POST["submit"]) &amp;&amp; (empty($_POST["username"]) || empty($_POST["password"]) || empty($_POST["id"]))) { $_SESSION['message'] = "enter all fields please!!!!"; } $selfLink = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $selfLink .= "?" . $_SERVER['QUERY_STRING']; } header('location: '.$selfLink); exit; } if (isset($_SESSION['message'])) { echo $_SESSION['message']; unset($_SESSION['message']); } ?&gt; </code></pre> <p>Note that the redirecting to the page itself seems a bit forced (using <code>$_SERVER['QUERY_STRING']</code> to fetch the current page's location). It works more intuitively if you know the file name or if you're redirecting to a different page after handling form input.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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