PHP - Dont go to next page if input is wrong
<p>I'm working with a .html and a .php. In the default.html the user must enter some info and when the button is clicked the html does a post to the default2.php.
In default2.php the data is checked and if it's correct it redirects the user to another page. The problem I'm having is when the data entered is wrong. 
I'm having two issues here:</p>

<ol>
<li>When the data is wrong I'm redirecting the user to the default.html, because if I don't do that, it will stay in default2.php and default2.php has nothing important for the user to see. I don't know if this is the best way to do this.</li>
<li>When the data entered is wrong, I want an echo message to the user in default.html. But I don't know how to trigger this from default2.php.</li>
</ol>

<p>How can I solve these two issues?
Thanks...</p>

<hr>

<h3>default.html:</h3>

<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;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;

&lt;/script&gt;

&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;PHP4&lt;/title&gt;
&lt;style type="text/css"&gt;
body {
    background-color: #CCC;
}
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;


&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;form id="form1" name="form1" method="post" action="default2.php"&gt;
  &lt;p&gt;
    &lt;label for="textfield1"&gt;User Name&lt;/label&gt;
    &lt;input type="text" name="username" id="username" /&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;label for="textfield2"&gt;Password&lt;/label&gt;
    &lt;input type="password" name="password" id="password" /&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;input type="submit" name="button1" id="button1" value="Submit"  /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &lt;label id="label1"&gt;
  &lt;/label&gt;&lt;/p&gt;
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  
&lt;/form&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;


&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<h3>default2.php:</h3>

<pre><code>&lt;?php
require 'connection.php';

  if (isset($_POST['button1'])) {

    $username_v = $_POST['username'];
    $password_v = $_POST['password'];

    // Then you can prepare a statement and execute it.    
    $stmt = $dbh-&gt;prepare("CALL login(?, ?)");
    $stmt-&gt;bindParam(1, $username_v, PDO::PARAM_STR); 
    $stmt-&gt;bindParam(2, $password_v, PDO::PARAM_STR); 

    // call the stored procedure
    $stmt-&gt;execute();

    if ($row = $stmt-&gt;fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) 
    {
          header("Location: main.php");
    }
    else
    {
        header("Location: default.html");
    }

  }
?&gt;
</code></pre>
