[SOLVED] Like to know how to pass a message when mutiple fields get verified

I solved this problem using the below code I wrote I don’t know it’s good or bad but it works.

<?php
/**
 * Created by PhpStorm.
 * User: SiNUX
 * Date: 9/13/14
 * Time: 9:44 PM
 */
include_once("hostcon.php");

$rName = validateInput(mysql_real_escape_string($_POST["name"]));
$nicName = validateInput(mysql_real_escape_string($_POST["nicname"]));
$age = validateInput(mysql_real_escape_string($_POST["age"]));
$bust = validateInput(mysql_real_escape_string($_POST["bust"]));
$size = validateInput(mysql_real_escape_string($_POST["size"]));
$height = mysql_real_escape_string($_POST["height"]);
$hair = validateInput(mysql_real_escape_string($_POST["hair"]));
$eyes = mysql_real_escape_string($_POST["eyes"]);
$nAtio = validateInput(mysql_real_escape_string($_POST["natio"]));
$dEscrip = validateInput(mysql_real_escape_string($_POST["desc"]));
$stdService = validateInput(mysql_real_escape_string($_POST["stdService"]));
$othService = validateInput(mysql_real_escape_string($_POST["othService"]));

//Adds data from the options array in to one line
$std = implode(", ",$stdService);
$oth = implode(", ",$othService);

function validateInput($frmData){
    $frmData = trim($frmData);
    $frmData = stripslashes($frmData);
    $frmData = htmlspecialchars($frmData);

    return $frmData;

}

//Initiate error
$errorCount = "";
if (empty($rName)) {
    $errorCount = $errorCount. "Name empty";
} else {
     if (!preg_match("/^[a-zA-Z]+$/", $rName)) {
          $errorCount = $errorCount . "Only Letters and White Space Allowed";
     }
}

if(empty($nicName)){
   $errorCount = $errorCount . ", Nick name is empty";
}else{
    if(!preg_match("/^[a-zA-Z)-9]*$/",$nicName)){
        $errorCount = $errorCount .", Only Letters, White Space and numbers Allowed";
    }
}
 /*if(empty($age)){
     $ageErr = "This Field is Required";
 }else{
     if(!preg_match("/^[0-125]"))
 }
*/

if($errorCount == "") {
//inserting data in to the data base
    $newModel = 'INSERT INTO `modeldetails`(`name`, `nicName`, `age`, `bust`, `height`, `hair`, `eyes`, `natio`, `descrip`, `stdService`, `otService`) VALUES(\'' . $rName . "','" . $nicName . "','" . $age . "','" . $bust . "','" . $height . "','" . $hair . "','" . $eyes . "','" . $nAtio . "','" . $dEscrip . "','" . $std . "','" . $oth . "')";

    $fireQuary = mysql_query($newModel);
//echo mysql_error();

    if ($fireQuary) {
        header("location:newmodel.php?msg=added");
        exit();
    } else {
        header("location:newmodel.php?msg=notadded");
        exit();
    }
}else{
    header("location:newmodel.php?error=".$errorCount);
}

Believe me when I say that it really helps to mention the problem you’re having when posting a help thread.

Judging by your regexes though, I can see that your first one is looking to match a single alphabetical letter only, along with no whitespace (which differs to what your error message states). Your second regex also does not cater for whitespace, though this time it is using a quantifier. The quantifier here doesn’t make much sense though, since your regex will find a match of 0 characters if none are alphabetical because the * quantifier denotes 0…* matches - you should be using the plus (+) quantifier for 1…* character matches.

I’d therefore change both of your regexes to the following:

/^[a-zA-Z ]+$/

If that hasn’t solved your issue, then please reply back with what you’re actually having problems with.