In my error checking code, when user leave empty field and submit a page, the page is refreshed with error message, but all other fields are losing their typed text since data is not inserted into db yet.
I possibly can sent inserted fields info with line
header( "location:useraccount.php?a=Create%20Account&error=".$error . $_POST[field]);
But, there are 10 fields, and header “location: line would be too long. Is there another way to do it in php?
Is there better solution, maybe using java script validate ()? Can you give an example, please?
I have two files:
- useraccount.php:
<form method="post" action="transact-user.php" >
<?php
if ( !empty($GET['error']) ){
echo nl2br(urldecode( $GET['error']))."br />";
}
?>
- transact-user.php:
if (empty($_POST['login_name'])) {
$error .= "Please+enter+Login+name%21%0D%0A";
}
if ( empty($error) ){
execute code;
}else{
header( "location:useraccount.php?a=Create%20Account&error=".$error);
break;
}
Thank you,