[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

jquery color toggle won't work

The code below always returns red, or incorrect as the css for the background of the text box.
The email in the database updates OK.
If I change the toggle statement to alert(resp); the popup shows "correct"

Any ideas why it won't work?
<script type="text/javascript">
$(document).ready(function() {
  $('#email').blur(function() {
    $.post('update-email.php',{email: $(this).val()}, function(resp){
      if (resp == 'correct')
        {
          $('#email').css('background-color', '#b6fd90');
        }
        else
        {
          $('#email').css('background-color', '#fd9090');
        };
    });
  });
});
 </script>
 
PHP
 
<?php
 include "includes/session.php";
 
$email = $_POST['email'];
list($userName, $mailDomain) = split("@", $email); // splits out email domain to allow its testing by checkdnsrr below
if((!eregi("^([[:alnum:]_%+=.-]+)@([[:alnum:]_.-]+)\.([a-z]{2,3}|[0-9]{1,3})$",$email) OR  !checkdnsrr($mailDomain, "MX")) AND $email>"")
{
 echo"incorrect";
}else{
$updateLogin = "UPDATE users
      SET paypal='$email'
      WHERE username='" . $_SESSION['username'] . "'";
$loginUpdated = mysql_query($updateLogin) or die("Update died because: " . mysql_error());
  if($loginUpdated) {
            echo "correct";
      } else {
            echo "incorrect";
      }
}
?>
HTML
Change or Enter Your Email Address:<br /> <input id="email" type="text" name="email"  size="60" maxlength="60" value="<?echo $_SESSION['paypal']; ?>" />

Open in new window

0
birwin
Asked:
birwin
  • 2
1 Solution
 
David S.Commented:
Try changing

  if($loginUpdated) {

to

  if(mysql_affected_rows() >= 1) {
0
 
birwinAuthor Commented:
Hi Kravimir:
I don't think that's the issue, since if I change the query to remove the
if (resp == 'correct')
        {
          $('#email').css('background-color', '#b6fd90');
        }
        else
        {
          $('#email').css('background-color', '#fd9090');
        };

and replace it with alert(resp);
it shows the "correct" as the alert message, so obviously the PHP has worked and returned the proper value.
0
 
David S.Commented:
Well, I don't see anything else that might cause this to not work.

Debugging code just by reading it is hard. We would be better able to help you if you could post a link to a live example.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now