Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
include "validation.php3";
?>
<HTML>
<BODY class=visit>
<TABLE width=100% border=0>
<form action="arform.php3?arid=<? print "$arid"; ?> " target="_self" method=post>
<tr><td>Username</td><td><INPUT TYPE="text" name=arname value="<? print "$arname"; ?>" size=20></td><td><? print $error['arname']; ?></td></tr>
<tr><td>E-mail</td><td><INPUT TYPE="text" name=aremail value="<? print "$aremail"; ?>" size=20></td><td><? print $error['aremail'] ; ?></td></tr>
<tr><td><input type="hidden" name="process" value="1"></td></tr>
<tr><td><input type="hidden" name="formname" value="artistform"></td></tr>
<tr><td colspan=3><input type="Submit" value="Submit" name="Submit"></td></tr>
</td></tr>
</TABLE>
</BODY>
</HTML>
CREATE TABLE `validationrulestable` (
`vrid` int(11) NOT NULL auto_increment,
`vrname` varchar(20) NOT NULL default '',
`vrdescr` tinytext NOT NULL,
`vrquery` text,
PRIMARY KEY (`vrid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `validationrulestable` VALUES (1, 'notempty', 'Field may not be empty', 'SELECT length(''$fieldvalue1'') = 0');
INSERT INTO `validationrulestable` VALUES (2, 'validemail', 'Email adress is not correct', 'SELECT ''$fieldvalue1'' not like ''%@%.%''');
INSERT INTO `validationrulestable` VALUES (3, 'useralreadyexist', 'username already exists', 'SELECT count(arname) from artisttable where arname like ''$fieldvalue1''');
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}