www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30

Thread: Error Error .... Please help me i am stuck!!!1

  1. #16
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    851
    Not according to the code you posted.

    I've done what I can. Good by.

  2. #17
    Join Date
    Mar 2014
    Posts
    70
    <?php echo $Object->ErrMsg['name']; ?>
    <?php echo $Object->ErrMsg['email']; ?>


    just tell me why undefined index?

  3. #18
    Join Date
    Mar 2014
    Posts
    70
    <?php echo $Object->ErrMsg['name']; ?> Undefined index: name in ..... on line 175
    <?php echo $Object->ErrMsg['email']; ?> Undefined index: email in ..... on line 179

    just tell me why....

  4. #19
    Join Date
    Mar 2012
    Posts
    1,740
    Seems to me there is a potential problem in your very first line of code:

    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

    You have used double quotes inside double quotes. Perhaps you should try:

    <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">

    P.S. I realize that in PHP single quotes act differently to double quotes. An alternative may be to rewrite your code something like:

    <?php $self= htmlspecialchars($_SERVER["PHP_SELF"]);?>
    <form method="post" action="<?php echo $self;?>">


    Of course, there could be similar problems elsewhere in your code, so this alone may not solve it, but it might help!

  5. #20
    Join Date
    Mar 2014
    Posts
    70
    i tried but still i have the same index problem...
    <?php echo $Object->ErrMsg['name']; ?> Undefined index: name in .....
    <?php echo $Object->ErrMsg['email']; ?> Undefined index: email in .....

  6. #21
    Join Date
    Mar 2014
    Posts
    70
    how to check the array on page load that ErrMsg array is empty and after show the messages.. that what i have understood

  7. #22
    Join Date
    Mar 2012
    Posts
    1,740
    There seems to be a couple of discrepancies in the code you posted in #9:


    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    <label for="name">Your name:</label>
    <input type="text" name="name" class="form-control" id="userName" value="<?php echo htmlspecialchars($name);?>" />
    <br /><?php echo $RegObject->ErrMsg['name']; ?>

    <label for="email">Your email:</label>
    <input type="text" name ="email" id="userEmail" class="form-control" value="<?php echo htmlspecialchars($email);?>" />
    <br /><?php echo $Object->ErrMsg['email']; ?>
    <form>

    In both inputs you have used different IDs from the NAMEs. Why? Hopefully if you use ...name="name" id="name"... and ...name="email" id="email"... that might solve the errors.

  8. #23
    Join Date
    Mar 2014
    Posts
    70
    that id nothing to to do with id when we post our data it is retrieved by name not by id as far as i know?.. more i have problem with ErrMsg array...

  9. #24
    Join Date
    Mar 2012
    Posts
    1,740
    As far as I am aware, it is generally considered advisable, where both name and ID are set, to set them the same. At the very least it minimizes the likelihood of browser-specific discrepancies. Anyway, you have not said whether you tried amending the code as suggested?

  10. #25
    Join Date
    Mar 2014
    Posts
    70
    no i also tried with this but still getting error... but i tried something else
    $Object->ErrMsg['name'] = "";

    out side my if(isset($_POST)){

    }

    //and then used that error messages at the front of my fields.. somebody told me to initialize first.. i don't know wether this is right approach or not?

    but now i am not getting the index problem... but now code duplication.....

  11. #26
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    851
    Can you post your CURRENT version of your code with the line numbers so that I can take a fresh look?

    If not, then I won't bother to respond.

  12. #27
    Join Date
    Mar 2014
    Posts
    70
    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    <label for="name">Your name:</label>
    <input type="text" name="name" class="form-control" id="userName" value="<?php echo htmlspecialchars($name);?>" />
    <br /><?php echo $RegObject->ErrMsg['name']; ?>

    <label for="email">Your email:</label>
    <input type="text" name ="email" id="userEmail" class="form-control" value="<?php echo htmlspecialchars($email);?>" />
    <br /><?php echo $Object->ErrMsg['email']; ?>

    <input type ="submit" value ="Send" id="submit" name ="submit"/>
    <?php echo $Success; ?>
    <form>




    //functions from class
    public function ValidationCheck($input){

    if (!preg_match("/^([a-zA-Z ]{3,30})*$/",$input["name"])){
    $this->ErrMsg['name'] = '<div class="error">Please Give your Real Name</div>';
    $this->ErrorLog = True;
    }
    if (!preg_match("/^([a-zA-Z ]{3,30})*$/",$input["email"])){
    $this->ErrMsg['email'] = '<div class="error">Please Give your email</div>';
    $this->ErrorLog = True;
    }
    }

    public function error(){
    return $this->ErrorLog ;
    }

    //class ends


    $Success ="";
    $Object->ErrMsg['name'] = ""; ------------------ here i initialize
    $Object->ErrMsg['email'] =""; ........................ here i initialize

    if(isset($_POST)){

    $RequiredFields = array('name' => $name,'email' => $email );
    $Object->ValidationCheck($RequiredFields);

    $Object->ValidationCheck($input)
    if(!($Object->error()))
    {
    $Success="SuccessFul";
    }
    }

  13. #28
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    851
    This is YOUR code from your latest post #27. So there is no confusion about what I'm pointing I've placed my comments in caps with the code. (PS - this code has errors in it and does not run as shown here but I'll ignore that for now)

    PHP Code:
    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
    <label for="name">Your name:</label>
    <input type="text" name="name" class="form-control" id="userName" value="<?php echo htmlspecialchars($name);?>" />
    <br />
    <?php 
    // HERE YOU GET MSG FROM OBJECT  # 1
    echo $RegObject->ErrMsg['name'];     
    ?>
    <label for="email">Your email:</label>
    <input type="text" name ="email" id="userEmail" class="form-control" value="<?php echo htmlspecialchars($email);?>" />
    <br />
    <?php 
    // HERE YOU GET MSG FROM OBJECT  # 2
    echo $Object->ErrMsg['email'];         
    ?>
    <input type ="submit" value ="Send" id="submit" name ="submit"/>
    <?php echo $Success?>
    <form>
    //************************
    //functions from class
    public function ValidationCheck($input)
    {
        if (!preg_match("/^([a-zA-Z ]{3,30})*$/",$input["name"]))
       {
            $this->ErrMsg['name'] = '<div class="error">Please Give your Real Name</div>';
            $this->ErrorLog = True;
        }
        if (!preg_match("/^([a-zA-Z ]{3,30})*$/",$input["email"]))
       {
            $this->ErrMsg['email'] = '<div class="error">Please Give your email</div>';
            $this->ErrorLog = True;
        }
    }
    public function error()
    {
         return $this->ErrorLog ;
    }
    //class ends 
    $Success =""; 
    // HERE YOU INITIALZE OBJECT #2 ABOVE
    $Object->ErrMsg['name'] = "";     
    $Object->ErrMsg['email'] =""; 
    if(isset($_POST))
    {
        $RequiredFields = array('name' => $name,'email' => $email );
        // HERE YOU SET PROPS OF OBJECT #2 ABOVE
        $Object->ValidationCheck($RequiredFields);        
        // HERE YOU HAVE INVALID ARGUMENT  ?? $INPUT??
        //  SO IT WIPES OUT THE SETTINGS YOU JUST MADE.
        $Object->ValidationCheck($input)    // missing semi-colon here            
        if(!($Object->error()))                            
        {
                      $Success="SuccessFul";
        }
    }
    So - you are trying to show messages in your html from two objects, only one of which has been validated.
    Plus - you are calling your validation method with an argument - $input - that appears nowhere else in this code and assign the results of that to the same object properties.

  14. #29
    Join Date
    Mar 2014
    Posts
    70
    my code is running fine just tell me .. is this approach to initialize the variables is correct or not ....
    $Object->ErrMsg['name'] = "";
    $Object->ErrMsg['email'] ="";

  15. #30
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    851
    If your code is running fine, then you must have made the needed changes. Congratulations.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles