仅使用PHP发送POST值

I want to use my webpage to recognize if a $_POST is set and the, if it is, print it in the page, so this is what I really have now:

if (isset($_POST['error'])) {
    echo '<div id="error">'.$_POST['error'].'</div>';
}

But what I want is that, when an if statement that I have in the same document returns true, to send a POST request to that same file and so, show the error message with the $_POST. Is this possible or it is another easy way for doing it?

Sorry for not explaining so well, this is my code:

if (password_verify($_POST['oldpassword'], $result['password'])) {
    // Upload password to database
} else {
    // Set the $_POST['error'] to an error message so I can show it in the error DIV.
}

Thanks!

You can define a $message athe beginning of your page then handle the errors you want to show

$message = '';
if (password_verify($_POST['oldpassword'], $result['password'])) {
   // Upload password to database
} else {
   //set a proper message ID which will be handled in your DIV
   $message_id = 1;
   header('location: /current_path.php?message='.$message_id);
}

Now in the div you can show it as

if (!empty($_GET['message'])) {
   echo '<div id="error">';
   if ($_GET['message'] == 1) { echo 'First message to show.'; }
   elseif ($_GET['message'] == 2) { echo 'Second message to show.'; }
   echo '</div>';
}