Displaying Errors In a Form
Posted: Sun May 08, 2005 12:05 am
I want to display errors by using a function I made (located on function.php):
Here is the form error checking:
I'm getting errors about the foreach. I need a push in the right direction, many thanks.
Code: Select all
function error($errors){
if($errors){
return "<table width=\"250\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr bgcolor=\"#990000\">
<td><div align=\"center\"><font color=\"#CCCCCC\"><strong>Please Fix the Following
Errors</strong></font></div></td>
</tr>
<tr bgcolor=\"#990000\">
<td bgcolor=\"#333333\"><ul>"
foreach($errors[] as $fix => $value){
return implode("<li></li>",$fix);
}
return "</ul></td></tr></table>";
}else{
$error = 0;
return $error;
}
}Code: Select all
include_once('function.php');
$errors = array();
if($atopcommander == ""){
$atopcommander = 'none';
}
$addcheck = mysql_query("SELECT * FROM `farms` WHERE username = '$ausername'") or die(mysql_error());
if(mysql_num_rows($addcheck) !== 0){
$errors[] = "Farm Already In Database";
}
if($ausername = "" && $daefenceaction == "" && $aarmysize == "" && $astatid == ""){
$errors[] = "Please Fill In All Fields";
}
if((!is_numeric($adefenceaction)) && (!is_numeric($aarmysize))){
$errors[] = "Please Recheck Defence Action and Armysize.";
}
if((strlen($astatid) <= 6) && (!is_numeric($astatid))){
$errors[] = "Please Check Stat ID.";
}
error($errors);
if($error == 0){
$timeadd = time();
mysql_query("INSERT INTO farms (id, username, topcommander, defenceaction, armysize, statid, comments, author, time) VALUES(NULL, '$ausername', '$atopcommander', '$adefenceaction', '$aarmysize', '$astatid', '$acomments', '$author', '$timeadd')") or die(mysql_error());
mysql_query("UPDATE users SET farmcount = farmcount + 1 WHERE user = '$username' LIMIT 1") or die(mysql_error());
print "Farm Was Added To Database";
}