Show Errors User Defined Function with flash
1. show_errors()
<?php
//Error Library
$msg['auth-failed'] = '* You sent a Illegal Request';
$msg['invalid-btn'] = '* Submit Only Allowed By submit Btn';
$msg['blank-email'] = '* Email cannot be Empty';
$msg['blank-password'] = '* Password cannot be Empty';
$msg['login-failed'] = 'Invalid username(Email) or Password';
function show_errors($action='')
{
global $msg;
$keyname = @$_REQUEST['msg'];
$error=@$msg[$keyname];
$request_action = @$_REQUEST['action'];
if($action==$request_action and !empty($action)){
echo "<span style='color:red' id='spn-error'>$error</span>";//Main Varible
echo "<script>";
echo "setTimeout(function(){
document.getElementById('spn-error').style='display:none;';
},5000);";
echo "</script>";
}//action compare
if($action=='' and $request_action==NULL){
echo "<span style='color:red' id='spn-error'>$error</span>";//Main Varible
echo "<script>";
echo "setTimeout(function(){
document.getElementById('spn-error').style='display:none;';
},5000);";
echo "</script>";
}
}
2. show_errors()
<?php$msg['auth-failed']= '* You sent a Illegal Request';$msg['invalid-btn']= '* Submit Only Allowed By submit Btn';$msg['invalid-name']= '* Invalid Name';$msg['invalid-mobile']= '* Invalid Mobile';function show_errors($action=''){///---------------------------------------global $msg;$keyname = @$_REQUEST['msg'];$error=@$msg[$keyname];//-----------------------------------------$request_action = @$_REQUEST['action'];if($action==$request_action and !empty($action)){echo "<span style='color:red'>$error</span>";//Main Varible}//action compareif($action=='' and $request_action==NULL){echo "<span style='color:red'>$error</span>";//Main Varible}}
exam-practice.php
<?phpinclude 'errorss.php';?><html><head></head><body><?php show_errors()//argument = 0 default case '';?><h1>Vaidation Practice</h1><form method="post" action="output.php?/=<?php echo basename($_SERVER['PHP_SELF']);?>">Name:<input type="text" name="name"><?php show_errors('name');?></br>Email:<input type="text" name="mobile"><br><?php show_errors('mobile');?><input type="submit" name="btn" value="submit"></form></body></html>
output.php
<?php#validate.phpif($_SERVER['REQUEST_METHOD']=='POST'){if(isset($_POST['btn']) and !empty($_POST['btn'])){$name = isset($_POST['name'])?$_POST['name']:NULL;$mobile = isset($_POST['mobile'])?$_POST['mobile']:NULL;if(is_null($name) or empty($name)){header("location:{$_REQUEST['/']}?action=name&msg=invalid-name");}elseif(is_null($mobile) or empty($mobile)){header("location:{$_REQUEST['/']}?action=mobile&msg=invalid-mobile");}}else{header("location:{$_REQUEST['/']}?msg=invalid-btn");}}else{header("location:{$_REQUEST['/']}?msg=auth-failed");}
validate.php
<?php#validate.phpif($_SERVER['REQUEST_METHOD']=='POST'){if(isset($_POST['btn']) and !empty($_POST['btn'])){$email = isset($_POST['email'])?$_POST['email']:NULL;$password = isset($_POST['password'])?$_POST['password']:NULL;if(is_null($email) or empty($email)){header("location:{$_REQUEST['/']}?action=email&msg=blank-email");}elseif(is_null($password) or empty($password)){header("location:{$_REQUEST['/']}?action=password&msg=blank-password");}else{//Every thing validatedif($email=='awnish@gmail.com' and $password=='1234'){echo 'Welcome to the Dashboard';}else{header("location:{$_REQUEST['/']}?msg=login-failed");}}}else{header("location:{$_REQUEST['/']}?msg=invalid-btn");}}else{header("location:{$_REQUEST['/']}?msg=auth-failed");}
0 Comments