SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why this code always evaluate to true?

    Hi

    I have the following php

    PHP Code:
    public function checkEmail()
            {     
                
    // set the validation rules
                
    $this->form_validation->set_rules('checkemail''E-Mail''valid_email');
                
    $this->form_validation->set_error_delimiters('<br /><p class=jsdiserr>''</p><br />');
                
    // if validation is passed
                
    if ($this->form_validation->run() !== FALSE
                {
                    
    $ids=array();
                    
    $ids[0]=$this->db->where('email'$this->input->post('checkemail'));

                    
    $query $this->backOfficeUsersModel->get();
                    if(
    $query) {
                   
                        
    $data = array(
                            
    'userid'      => $query[0]['userid'],
                            
    'username'    => $query[0]['username'],
                            
    'password'    => $query[0]['password'],
                            
    'firstname'   => $query[0]['firstname'],
                            
    'lastname'    => $query[0]['lastname'],
                            
    'email'       => $query[0]['email']            
                        ); 
                         
                        
    $message "#successMailMessage";
                        
                    } else {
                         
                       
                        
    $message "#errorMailMessage";
                       
                         
                        
                    }
                    
                     
    $output '{ "message": "'.$message.'" }';
                     echo 
    $output;
                        
    //  form validation has failed 
                
    } else {     
                    
    $errorMessage "Wrong email!";
                    
    //echo json_encode(array("success" => "false"));
                       
                
    }
            }   
    // end of function checkEmail 
    Now, here, if i output the output, result is correct, that is if the e-mail exists in the database the output is #successMailMessage, if not the output is #errorMailMessage

    Now, here is the javascript code:

    Code:
     $("#formSendPassword").submit(function(e){     
               e.preventDefault();
               var email = $(this).find("#checkemail").val();  
               var url = $(this).attr("action");
          
           $.ajax({
            type: "POST",
            url: $(this).attr("action"),
            dataType: "json",
            data: "email="+email,
            cache:false,
            success: 
              function(output){
                 console.log(output.message);
                 $('#forgotPasswordForm').hide();
                 $(output.message).fadeIn();
                 // add those in the variable message somehow later
              } 
            });
              
          return false;
          });
    Here, i always get successMailMessage in the console.log, hence the successMailMessage div fades in. If i disable the javascript, i get correct output in PHP
    Can anyone help me with this?

    Regards,zoreli

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Why not amend your code to include the email address that was tested in the message being returned - that way you can confirm whether the script is testing the email address you think it is. From the look of the part of the code you have provided I suspect the problem is that the right email address is not being sent by the JavaScript.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Perhaps I'm a bit dense today, but this:


    $query = $this->backOfficeUsersModel->get();
    if(
    $query
    ) {

    looks like you are assigning a value and then asking if a value exists...which should always be true.

    Where the World Once Stood
    the blades of grass
    cut me still

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Vincent Puglia View Post
    Hi,

    Perhaps I'm a bit dense today, but this:


    $query = $this->backOfficeUsersModel->get();
    if(
    $query
    ) {

    looks like you are assigning a value and then asking if a value exists...which should always be true.

    Hi Vincent

    Thanks for your answer.

    Code that you quote is from CodeIgniter controller. I first call function within the model, and then i just test if the query return any results. That part work, i tested it many times with echoing the values.

    As i wrote above if I disable the javascript, i get proper values, that is if the e-mail exists in the database, i get correct message, and oposite, if e-mail do not exist in the datbase, i get appropriate message printed. My problem lies in the javascript file, since there, no matter what i do, value is alvays evaluate to successMessage, even when in the php is printed errormessage.

    That is the reason why i post this in jquery forum.

    Regards,Zoran

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Stephen

    Why not amend your code to include the email address that was tested in the message being returned - that way you can confirm whether the script is testing the email address you think it is. From the look of the part of the code you have provided I suspect the problem is that the right email address is not being sent by the JavaScript.
    I will give it a shoot tomorrow morning, now is 3:00AM here. I will post the outcome here if i come out with something.

    Regards,Zoran


Bookmarks

Posting Permissions

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