$newNotes = trim($_POST['myNotes']); $newCUsername = trim($_POST['cUsername']); $newCPassword = trim($_POST['cPassword']); //check for empty first name/company name if (emptyTest($newFname)) { $namescheck = true; } else { $error = $error . "First Name Required!"; } //check email if (emailCheck($newEmail)) { $emailcheck = true; } else { $error = $error . "Invalid Email."; } if (phoneCheck($newPhone, 10)) { $telephonecheck = true; } else { $error = $error . "Invalid Phone."; } if ($emailcheck == true && $namescheck == true && $telephonecheck == true) { //insert into database $sql = "INSERT INTO Aegis_Client (FirstName, LastName, EandO, CompanyPhone, ContactPerson, ContactPhone, Email, WebsiteURL, Notes, CompanyUsername, CompanyPassword) VALUES('" . $newFname . "','" . $newLname . "','" . $newEO . "','" . $newPhone . "','" . $newCperson . "','" . $newCPhone . "','" . $newEmail . "','" . $newWebsite . "','" . $newNotes . "','" . $newCUsername . "','" . $newCPassword . "')"; $result = mysqli_query($con, $sql) or die("Error in the consult.." . mysqli_error($con)); //send the query to the database or quit if cannot connect //add our elements to the the respective arrays //initialize variables $index = 0; //fname first $index = count($_SESSION['Fname']); // should give us the next available index to use
function dataCheck($checkArr = array()) { //验证类型 switch ($checkArr['checkType']) { //非空 case 'notnull': if (empty($checkArr['field'])) { return false; } break; //只能是数字 //只能是数字 case 'number': //数字字符串验证 if (!is_numeric($checkArr['field'])) { return false; } //数字长度验证 if (is_numeric($checkArr['length'])) { if (strlen($checkArr['field']) != $checkArr['length']) { return false; } } else { @(list($minlength, $maxlength) = explode('-', $checkArr['length'])); if (strlen($checkArr['field']) < $minlength or strlen($checkArr['field']) > $maxlength) { return false; } } break; //只能是字符串 //只能是字符串 case 'string': break; //只能是数字+字符串 //只能是数字+字符串 case 'numberstring': break; //非0 //非0 case 'not0': if ($checkArr['field'] == 0) { return false; } break; //记录存在 //记录存在 case 'unique': $table = ucwords($checkArr['table']); $model = model($checkArr['table']); $checkData = array('condition' => array($checkArr['field'] => trim($checkArr['value']))); if ($model->find($checkData)) { return false; } break; //邮箱真实 //邮箱真实 case 'email': if (!emailCheck($checkArr['field'])) { return false; } break; //手机号 //手机号 case 'phone': if (!phoneCheck($checkArr['field'])) { return false; } break; //字符长度 //字符长度 case 'length': if (strlen($checkArr['field']) < $checkArr['minlength'] or strlen($checkArr['field']) > $checkArr['maxlength']) { return false; } break; //字段相等 //字段相等 case 'equal': if ($checkArr['field'] != $checkArr['field2']) { return false; } break; //等于指定值 //等于指定值 case 'eqvalue': if ($checkArr['field'] == $checkArr['value']) { return false; } break; //条件验证记录存在 //条件验证记录存在 case 'exists': $model = model($checkArr['table']); if ($model->find($checkArr['condition'])) { return false; } break; default: return false; break; } return true; }