title: Display error message PHP Mysql
body: <p>i am unable to get the last 2 echos to work, even if the update query fails it still displays success. If anyone has any suggestions on this code to be improved on any line, please do!</p>
  
  <pre><code>&lt;?php
          if(!empty($_POST['username']) &amp;&amp; !empty($_POST['answer']))  { 
              $username = $_POST['username'];
              $idfetch = mysql_query("SELECT id FROM users WHERE username ='$username'") //check it
              or die(mysql_error());
              $fetched = mysql_fetch_array($idfetch);  
              $id = $fetched['id']; //get users id for checking
              $answer = $_POST['answer'];
              $password = (mysql_real_escape_string($_POST['password']));
              $confpass = (mysql_real_escape_string($_POST['confpass']));
              if ($password != $confpass) {
                  echo ("Passwords do not match, please try again.");
                  exit;
              }
              $updatequery = mysql_query("UPDATE users SET PASSWORD='$password' WHERE id='$id' AND username='$username' AND answer='$answer'");
              if($updatequery)  {  
                  echo "&lt;h1&gt;Success&lt;/h1&gt;";  
                  echo "&lt;p&gt;Your account password was successfully changed. Please &lt;a href=\"login.php\"&gt;click here to login&lt;/a&gt;.&lt;/p&gt;";  
              }  
              else  {  
                  echo "&lt;h1&gt;Error&lt;/h1&gt;";  
                  echo "&lt;p&gt;Sorry, but a field was incorrect.&lt;/p&gt;";  
              }  
         } 
  ?&gt;
  </code></pre>
  
  <p>Thanks in advance! </p>