Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    166
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Date time validation at server side

    Hi Friends,

    I am having 4 fields with Jquery date time picker and I want to validate each field entry before posting it into DB.

    and i am looking for a FOR loop to execute it.

    My business rules is:

    a) User will not fill all the values at same time.
    b) second field date cannot be lesser then first field date & third field date cannot be less date then second field date, In the same way fourth field date cannot be less then third field date.
    c) All feild should be editable respectively with above (b) conditions.

    I have below code written but I am doing mistake which is not functioning as required any help is appreciated.

    PHP Code:
    <?
    $test
    =$_REQUEST['test'];
    //Connecting DB
    include_once "C:/xampp/htdocs/sam/include/db.php";

    //Values from the form 
    $process $_POST['aging']; $istc=$_REQUEST['istc']; $istcr=$_REQUEST['istcr'];
    $process2 =$_REQUEST['aging2']; $secnd =$_REQUEST['secnd'];$secndr =$_REQUEST['secndr'];

    //print_r($istcr);
                                                    
                            
    $array=array($istc[$test],$istcr[$test],$secnd[$test],$secndr[$test]);
                            
    //print_r($array);
                            
                            
    foreach ($array as $key1=>$value1){
                                 
    $i=0;
                                
    $j=1;
                                if(
    strtotime($array[$j]) <= strtotime($array[$i])){
                                    
    $_SESSION['Notify']['type'] = 'error Message:';
                                    
    $_SESSION['Notify']['msg'] = "$array[$j]</b> cannot be lesser then $array[$i]!!!";
                                    
    header("location:".$url)or die("record not inserted");
                                }        
                                
    $i++;
                                
    $j++;
                            
                            
            
    //Inserting form values in to db table                                                    //print_r($process); 
            
    foreach($process as $key=>$value){$key;
                
    //if(!empty($value) && $value!='--'){    
                    //if($istcr[$key]>$istc[$key]){                                                        
                    
    $qry ="UPDATE $ticket_aging SET 1st_contact_point='".mysql_real_escape_string($value)."',
                               `1st_contact`= '"
    .mysql_real_escape_string($istc[$key])."',`1st_contact_reply`='".mysql_real_escape_string($istcr[$key])."', 
                                2nd_contact_point='"
    .mysql_real_escape_string($process2[$key])."',2nd_contact='".mysql_real_escape_string($secnd[$key])."',`2nd_contact_reply`='".mysql_real_escape_string($secndr[$key])."',
                                where sno='$key'"
    ;

    }
    }            
    mysql_close();
    ?>
    Regards,
    nani
    Attached Thumbnails Attached Thumbnails Date time validation at server side-sample.jpg  
    Last edited by nani_nisha06; 02-28-2013 at 03:36 AM.

  • #2
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    166
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by nani_nisha06 View Post
    Hi Friends,

    I am having 4 fields with Jquery date time picker and I want to validate each field entry before posting it into DB.

    and i am looking for a FOR loop to execute it.

    My business rules is:

    a) User will not fill all the values at same time.
    b) second field date cannot be lesser then first field date & third field date cannot be less date then second field date, In the same way fourth field date cannot be less then third field date.
    c) All feild should be editable respectively with above (b) conditions.

    I have below code written but I am doing mistake which is not functioning as required any help is appreciated.

    PHP Code:
    <?
    $test
    =$_REQUEST['test'];
    //Connecting DB
    include_once "C:/xampp/htdocs/sam/include/db.php";

    //Values from the form 
    $process $_POST['aging']; $istc=$_REQUEST['istc']; $istcr=$_REQUEST['istcr'];
    $process2 =$_REQUEST['aging2']; $secnd =$_REQUEST['secnd'];$secndr =$_REQUEST['secndr'];

    //print_r($istcr);
                                                    
                            
    $array=array($istc[$test],$istcr[$test],$secnd[$test],$secndr[$test]);
                            
    //print_r($array);
                            
                            
    foreach ($array as $key1=>$value1){
                                 
    $i=0;
                                
    $j=1;
                                if(
    strtotime($array[$j]) <= strtotime($array[$i])){
                                    
    $_SESSION['Notify']['type'] = 'error Message:';
                                    
    $_SESSION['Notify']['msg'] = "$array[$j]</b> cannot be lesser then $array[$i]!!!";
                                    
    header("location:".$url)or die("record not inserted");
                                }        
                                
    $i++;
                                
    $j++;
                            
                            
            
    //Inserting form values in to db table                                                    //print_r($process); 
            
    foreach($process as $key=>$value){$key;
                
    //if(!empty($value) && $value!='--'){    
                    //if($istcr[$key]>$istc[$key]){                                                        
                    
    $qry ="UPDATE $ticket_aging SET 1st_contact_point='".mysql_real_escape_string($value)."',
                               `1st_contact`= '"
    .mysql_real_escape_string($istc[$key])."',`1st_contact_reply`='".mysql_real_escape_string($istcr[$key])."', 
                                2nd_contact_point='"
    .mysql_real_escape_string($process2[$key])."',2nd_contact='".mysql_real_escape_string($secnd[$key])."',`2nd_contact_reply`='".mysql_real_escape_string($secndr[$key])."',
                                where sno='$key'"
    ;

    }
    }            
    mysql_close();
    ?>
    Regards,
    nani

    Any help guys....still stuck some where

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Does your form contain all four fields at the same time?
    Rule #1 specifies that these won't be filled out at the same time; should that instead be that not all four fields *have* to be filled out at the same time, or that only one field will ever be provided at a time?
    This task is trivial if all fields are filled out at the same time. Its simply a matter of comparing each entry in a goverend order (for which using input arrays may be easier to work with). But if you are only doing one at a time, you must first retrieve the existing stored values and compare it to that. Assuming that it must go in order of course. A simple function can do that:
    PHP Code:
    function isOrdered(array $a)
    {
        
    $curHighest null;
        
    $bOrdered true;
        
    reset($a);
        while (
    $bOrdered && ($cur current($a)))
        {
            if (
    $curHighest != null)
            {
                if (
    $curHighest <= $cur)
                {
                    
    $curHighest $cur;
                }
                else
                {
                    
    $bOrdered false;
                }
            }
            else
            {
                
    $curHighest $cur;
            }
            
    next($a);
        }
        return 
    $bOrdered;

    Doesn't cast as such, but assumes them to be comparable with <=, so it should be a number.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    166
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    Does your form contain all four fields at the same time?
    Rule #1 specifies that these won't be filled out at the same time; should that instead be that not all four fields *have* to be filled out at the same time, or that only one field will ever be provided at a time?
    This task is trivial if all fields are filled out at the same time. Its simply a matter of comparing each entry in a goverend order (for which using input arrays may be easier to work with). But if you are only doing one at a time, you must first retrieve the existing stored values and compare it to that. Assuming that it must go in order of course. A simple function can do that:
    PHP Code:
    function isOrdered(array $a)
    {
        
    $curHighest null;
        
    $bOrdered true;
        
    reset($a);
        while (
    $bOrdered && ($cur current($a)))
        {
            if (
    $curHighest != null)
            {
                if (
    $curHighest <= $cur)
                {
                    
    $curHighest $cur;
                }
                else
                {
                    
    $bOrdered false;
                }
            }
            else
            {
                
    $curHighest $cur;
            }
            
    next($a);
        }
        return 
    $bOrdered;

    Doesn't cast as such, but assumes them to be comparable with <=, so it should be a number.
    Thanks Fou-Lu,

    For above suggestion.

    To be more specific on the rule one i am adding small example below.

    Code:
    let say,
    
    I have 4 input fields with name A, B, C, D.
    
    At first when user opens the form he will enter value of A= 02/02/2013
    
    after 2 days he will enter another date in the field B as 04/02/2013, When he enter these value while it is stored in DB it should go validation that B date should not lesser date then A.
    
    After another 2 days I will enter C value as 06/02/2013, Now, before it getting in to DB it should go in to validation that C !<= A && C !<= B
    
    In the same way for D, but validation rule should be D !<= C && D !<= B && D!<=A.
    
    
    If above fails it should re direct else get the values stored in the DB.

    As I have 20 fields in my real application first i want to try the loop for 4 fields then implement it for all later.

    hope I am clear this time.

    Let me know if you need more information.

    Regards,
    Nani

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    723
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you can write javascript dynamically with php

    then load the values from the database and use onchange for the field to see if its greater than the last


    or just use onchange with the previous fields populated from the database but make them read only
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #6
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    166
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Arcticwarrio View Post
    you can write javascript dynamically with php

    then load the values from the database and use onchange for the field to see if its greater than the last


    or just use onchange with the previous fields populated from the database but make them read only
    Arcticwarrio,

    Can you please push some examples ....I am newbie on all this and trying all ways to solve this issue as self learner since 2 weeks and at last i have ended up in these forum for help.

    Really appreciate your help.

    Regards,
    Nani


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •