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);
}