I am a beginner at PHP and I am trying to build a register form for a project, I made all the validations possible, however I am stuck from here as where it should go, I want the form to validate all the following then submit if all is true.
PHP code:
<?php
//register form v1.0
error_reporting(0);
//declares register form
$formFields = array('reg-username' => 'اسم المستخدم',
'reg-email' => 'البريد الإلكتروني',
'reg-password' => 'كلمة المرور',
'reg-confirmPassword' => 'تأكيد كلمة المرور');
function checkBlank(){
global $formFields;
//now I want the browser to check each field if its empty
foreach($formFields as $fieldName => $fieldRealName){
if(empty($_POST[$fieldName])){
echo '<ul class="ErrorMessage"><li>لم تدخل '. $fieldRealName .' * </li></ul>';
echo '<style>.'. $fieldName .'{
border-color: red;
}
.'. $fieldName .'::-webkit-input-placeholder {
color: red;
}
.'. $fieldName .'-h{
color: red;
}
#asetrik{
display: none;
}
</style>';
}
}
}
//blank fields have been checked
function checkPass(){
$regPassword = $_POST['reg-password'];
$regConfPassword = $_POST['reg-confirmPassword'];
if($regPassword !== $regConfPassword){
echo '<ul class="ErrorMessage"><li>كلمات المرور غير متطابقة *</li></ul>';
} //if the fields are not empty i want it to check if the passwords match
}
function checkEmail(){
$regEmail = $_POST['reg-email'];
if (!filter_var($regEmail, FILTER_VALIDATE_EMAIL)) {
echo '<ul class="ErrorMessage"><li>البريد الإلكتروني المدخل غير صحيح *</li></ul>';
}
function checkName(){
$regUsername = $_POST['reg-username'];
if ( !preg_match('/^[A-Za-z][A-Za-z0-9]{5,31}$/', $regUsername)){
echo '<ul class="ErrorMessage"><li>اسم المستخدم يجب أن يبدأ بحرف *</li></ul>';
}
}
function checkExist(){
$regUsername = $_POST['reg-username'];
$regEmail = $_POST['reg-email'];
$connectToDB = mysql_connect('localhost', 'root', '') or die(mysql_error());
$selectDB = mysql_select_db('supermazad') or die(mysql_error());
$checkIfExist = mysql_query("SELECT * FROM users WHERE username LIKE '".$regUsername."' OR email LIKE '".$regEmail."' ");
if(mysql_num_rows($checkIfExist) > 0){
echo '<ul class="ErrorMessage"><li>اسم المستخدم/ البريد الإلكتروني موجود *</li></ul>';
}
}
?>