I read that for security reasons, the ideal is that the form data is validated two times ever. The first on the client side with javascript code and a second time on the server side with PHP code. The validation with javascript I have (almost) ready. However, I'm having problems with PHP validation ...

HTML Code:
<script type="text/javascript">
function frmRegisterValidate (){	
	var frmRegisterError = document.getElementById("frmRegisterError");
	var frmRegisterUN = document.getElementById("frmRegisterUN").value;
	var frmRegisterPW = document.getElementById("frmRegisterPW").value;
	if (frmRegisterUN == "")
			frmRegisterError.value = "Type your username";
			return false;
	else if (frmRegisterPW == "")
			frmRegisterError.value = "Type your password";
			return false;

<form method="post" action="frmRegister.php" id="frmRegister" name="frmRegister" accept-charset="utf-8">
  <label>Nombre de usuario: </label>
  <input type="text" id="frmRegisterUN" value="" name="frmRegisterUN" />
  <br />
  <label>Informe una contrasena: </label>
  <input type="text" value="" id="frmRegisterPW" name="frmRegisterPW">
  <br />
  <label>Se encontro un error: </label>
  <input type="text" value="" id="frmRegisterError" name="frmRegisterError"/>
  <br />
  <input type="button" value="REGISTER" id="frmRegister_Button" onClick="frmRegisterValidate ()"/>
PHP Code:
if (!empty ($_POST['frmRegisterUN'])) 

$frmRegisterUN $_POST['frmRegisterUN']; 


$frmRegisterUN NULL
"Type your username <br />"

if (!empty (

$frmRegisterPW $_POST['frmRegisterPW']; 


$frmRegisterPW NULL
"Type your password <br />"


This is a very simplified version of the form that I am developing. As you can see, I can do data validation in both javascript and PHP ...

My question is: with the PHP code, how should I do so that the error message is displayed in the value of the input called frmRegisterError equal to that done with javascript?