PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
When there is no data in the field, an error message stops the entry from being entered into the database. But I set the parameters for 14 number digits only and even if I put the wrong amount of digits, it will enter it into the database.
if(isset($submit_button)){
if(trim($vin)=='') {
$error_msg.="Please enter a VIN<br>";
} else {
// check if vin is 14 digits
if(!ereg("[0-9]{14}", $vin)) $error_msg.="Please enter a valid VIN #<br>";
}
if(trim($email)=='') {
$error_msg.="Please enter an email<br>";
} else {
// check if email is a valid address in this format username@domain.com
if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email)) $error_msg.="Please enter a valid email address<br>";
}
// display error message if any, if not, proceed to other processing
if($error_msg==''){
// other process here
} else {
echo "<font color=red>$error_msg</font>";
}
}
if (!empty($_GET["surname"]) &&
!empty($_GET["firstname"]) &&
!empty($_GET["email"]) &&
!empty($_GET["phone"]) &&
!empty($_GET["vin"]))
// bad
if(trim($vin)=='') {
$error_msg.="Please enter a VIN<br>";
} else {
// check if vin is 14 digits
if(!ereg("[0-9]{14}", $vin)) $error_msg.="Please enter a valid VIN #<br>";
}
// better
if(trim($vin)=='') {
$error_msg.="Please enter a VIN<br>";
} elseif(!ereg("[0-9]{14}", $vin)) {
$error_msg.="Please enter a valid VIN #<br>";
}