Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4023074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:33:15+00:00 2026-05-20T10:33:15+00:00

I’m struggling to understand how to get jQuery.ajax to interpret a failed MySQL UPDATE

  • 0

I’m struggling to understand how to get jQuery.ajax to interpret a failed MySQL UPDATE query as an error. Here’s my code:

jQuery:

$.ajax({
    type:'POST',
    url:'/ajax/registration.php',
    data:{formData: formData},
    success:function(data){eformDef.forms.registration.success(data);},
    error:function(data){eformDef.forms.registration.success(data);}
});

PHP

$data = $_POST['formData'];
$firstName = mysql_real_escape_string($data['first name']);
$lastName = mysql_real_escape_string($data['last name']);
$email = mysql_real_escape_string($data['email address']);
$password = mysql_real_escape_string($data['password']);


mysql_query("INSERT INTO users (first_name, last_name, email, password) VALUES ('$firstName', '$lastName', '$email', '$password')") or die(mysql_error());

No matter what–even if I make the mysql_query syntax invalid–the ajax call always interprets the response as a success. I assume that’s because the mysql_error() gets sent back as the response, the ajax call reads that as a string, and apparently considers that to be a success. Of course I can deal with this by checking the response string in the $.ajax success function, but this seems a bit illogical. In cases where I can test for a data type using the $.ajax dataType option, this isn’t an issue. But with an UPDATE query like the one above, I always get a string as a response.

Since there is a workaround (checking the string in the success function), this isn’t a critical issue. But if there is a more correct way of doing this, I’d much prefer that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:33:16+00:00Added an answer on May 20, 2026 at 10:33 am

    PHP will send a 200 OK status no matter what*, so there is no way to jQuery to detect an error.

    You have two possibilities:

    • Have the PHP script explicitly output something like “OK” or an JSON encoded array with a status code. Have the jQuery side explicitly look for that “OK” and throw an error if it’s not present.

    • Have the PHP script throw an error status code if an error occurs, for example:

        $query = mysql_query(......);
      
        if (!$query)
         {
           header("HTTP/1.1 500 Internal Server Error");
           echo mysql_error(); // Detailed error message in the response body 
           die();
         }
      

    * Except for this exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.