if ($_POST['process'] == 1) { // only process validation.php after it is submitted , process is a hidden field in the form
include $rootpath."cgi-bin/connopen.php3"; // connect to mysql
global $totalcheck; // variable which holds the total amount of errors
$query="SELECT * from validationrulestable"; // select all rules from the database
$rs=mysql_query($query,$conn);
$i=0;
$list = mysql_num_rows($rs);
while($i <= $list)
{
$row = mysql_fetch_array($rs);
// put every rule in an array with the short name provided like 'notempty'
$vrf[$row["vrname"]]['message']=$row["vrdescr"];
$vrf[$row["vrname"]]['query']=$row["vrquery"];
$i++;
}
// loop through all the post vars and convert them to variables with the same name and also in an array for further processing after totalcheck=0
while ( list($field, $value) = each ($HTTP_POST_VARS)){
$fieldvalues[$field]=$value;
$$field=$value;
global $$field; // to be able to print the values back in the form when there is something wrong
}
// function for checking the posted vars with the query
function controlesql($query,$fieldvalue1,$fieldname,$warning,$conn){
$query=str_replace("\$fieldvalue1",$fieldvalue1,$query);
$list2=mysql_result(mysql_Query($query,$conn),0);
// if list2 =1 then it's not good if 0 it's good
$error=array() ;
global $error;
// return the warning if list2 <> 0 or add the warning to previous checks that failed
if ($list2 == 0) {return 0;} else {$error[$fieldname] = $error[$fieldname] . "<br>". $warning; return 1;}
}
// FORM VERIFICATION
check the form with the checks you want to perform on the corresponding fields
// the formname is also a hiddenfield in the form. so you can easily process other forms in the validation.php
if ($formname == 'artistform') {
$totalcheck=0;
$totalcheck= $totalcheck + controlesql($vrf['notempty']['query'],$arname,"arname",$vrf['notempty']['message'],$conn);
$totalcheck= $totalcheck + controlesql($vrf['notempty']['query'],$aremail,"aremail",$vrf['notempty']['message'],$conn);
$totalcheck= $totalcheck + controlesql($vrf['useralreadyexist']['query'],$arname,"arname",$vrf['useralreadyexist']['message'],$conn);
$totalcheck= $totalcheck + controlesql($vrf['validemail']['query'],$aremail,"aremail",$vrf[validemail][message],$conn);
}
}// end if process=1
if ($totalcheck=0) { process information to mysql}