Why this code always evaluate to true?

Hi

I have the following php


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:


 $("#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

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.

Hi,

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

$query = $this->backOfficeUsersModel->getCOLOR=#007700;
if([/COLOR]$query
[COLOR=#007700][FONT=Courier New]) {

looks like you are assigning a value and then asking if a value exists…which should always be true.[/FONT]
[/COLOR]

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

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