title: Echo PHP message into a specific preloaded div?
body: <p>I'm having trouble getting an error message to output on the page I have already loaded. After the Log In button is pressed, I would like to check the input information, and if it is not correct return an error in a specific location without reloading the page. Is it possible to echo inside an element (such as inside my div as I am trying to do below)?</p>
  
  <pre><code>&lt;?php
  if (isset($_POST['login'])) { login(); }
  function login(){
      if(isset($_POST['username'])&amp;&amp;isset($_POST['password'])) {
          $username = $_POST['username'];
          $password = $_POST['password'];
          $password_hash=md5($password);
  
          if(!empty($username)&amp;&amp;!empty($password)) {
              //stuff
          } else {
              $loginerror = "You must supply a username and password";
          }
      }
  }
  ?&gt;
  
  &lt;div style="z-index: 10; float:right; margin-top: -20;"&gt;
      &lt;h3&gt;Already a user? Log in:&lt;/h3&gt;
      &lt;div&gt;&lt;?php if (isset($loginerror)){echo $loginerror;} ?&gt;&lt;/div&gt;
      &lt;form action="&lt;?php echo $current_file; ?&gt;" method="POST"&gt;
          &lt;div style="float: left; width: 80px;"&gt;Username:&lt;/div&gt; &lt;input type="text" name="username"&gt; &lt;br /&gt;
          &lt;div style="float: left; width: 80px;"&gt;Password:&lt;/div&gt; &lt;input type="password" name="password"&gt; 
          &lt;input type="submit" value="Log In" name="login"&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>