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

  • Home
  • SEARCH
  • 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 8295939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:47:24+00:00 2026-06-08T14:47:24+00:00

Am trying to write a new record using the jquery function. $.post(insertuser.php,$(#rohanStart).serialize(),function(data){ alert(data); });

  • 0

Am trying to write a new record using the jquery function.

$.post("insertuser.php",$("#rohanStart").serialize(),function(data){ 
    alert(data);
});

This seems to work and i do get an alert with the echo’ed statmenet. Problem is the values are not getting written into the database. Is there something wrong in the Query Statement?

mysql_query("INSERT INTO ajax_demo1( FirstName,LastName,Unit,Group,photo)
        VALUES (
            '".$arr['FirstName']."',
            '".$arr['LastName']."',
            '".$arr['Unit']."',
            '".$arr['Group']."',
            '".$arr['photo']."'
        )");

echo $arr['Group'];
  • 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-06-08T14:47:26+00:00Added an answer on June 8, 2026 at 2:47 pm

    First don’t use jQuery or any frameworks, they rely on the proprietary Microsoft JScript innerHTML method which does not work correctly with the DOM thus adding huge amounts of ambiguity in scripting.

    Secondly you’re NOT correctly escaping data going in to the database, that is a serious security issue.

    Thirdly your approach to database queries is not taking error handling in to account, you’re just dumping queries directly in and hoping for the best.

    You should ALWAYS number your queries and enclose them as I have below. Note that besides errors it is good to fail conditions up-front however with database structure you should execute if successful first and THEN fail to increase your indentation (by a single space, not this tab waste where you have five screens to horizontally scroll) so you can visualize where you are in your own code.

    $query1 = "SELECT * FROM table_name WHERE something='value'";
    $result1 = mysql_query($query1);
    
    if ($result1)
    {
     $row1 = mysql_fetch_assoc($result1);
    }
    else {mysql_error_report($query1,mysql_error(),__FUNCTION__);}
    

    If your main header includes (you DO have a main header being included for all requests except AJAX correct?) you should have a universal MySQL error handling function that you can use to log SQL errors.

    The following is the universal database error handler. You should have administrative error logs for HTTP, JavaScript, PHP and SQL errors so you can review and correct issues that your visitors encounter instead of if they only inconvenience you.

    function mysql_error_report($q,$e,$f)
    {
     if (isset($_SESSION['database']))
     {
      if (isset($_SESSION['id_member'])) {$id = $_SESSION['id_member'];} else {$id = 0;}
      if (isset($_SESSION)) {$session = mysql_real_escape_string(session_id());} else {$session = 0;}
      $ip = mysql_real_escape_string(getenv('REMOTE_ADDR'));
    
      $query = mysql_real_escape_string($q);
      $error = mysql_real_escape_string($e);
      $function = mysql_real_escape_string($f);
      if (isset($_SESSION['type'])) {$type = mysql_real_escape_string($_SESSION['type']);} else if (isset($_SESSION['cms_browser'])) {$type = 'Browser';} else {$type = 'Unknown';}
      if (isset($_SERVER['REQUEST_URI'])) {$url = $_SERVER['REQUEST_URI'];} else {$url = '';}
      if (isset($_SERVER['HTTP_USER_AGENT'])) {$ua = mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']);} else {$ua = '';}
    
      $query1 = "INSERT INTO log_errors_sql (id_session, type, id_user, date, ip, function, mysql_error, mysql_query, url, user_agent) VALUES ('$session', '$type', '$id', NOW(), INET_ATON('$ip'), '$function', '$error', '$query', '$url', '$ua')";
      $result1 = mysql_query($query1);
    
      if (!$result1) {mysql_error_report_mail($q,$e,$f,$ua);}
     }
     else {mysql_error_report_mail($q,$e,$f);}
    }
    

    By using that approach you’ll strengthen your coding practices to be much stricter. You don’t want ambiguity, you want to be a total tightass about your code because the less subjectivity there is in your coding the more your code will be able to handle.

    Also your white-space is very loose.

    This…

    INSERT INTO ajax_demo1( FirstName,LastName,Unit,Group,photo)
    

    Should be formatted like this…

    INSERT INTO ajax_demo1(FirstName, LastName, Unit, Group, photo)
    

    You might ask why keeping your white-space like that is important, if you haven’t spent a ton of time with find and replace (look up “Advanced Find & Replace”, it works on wine/Linux and blows the crap away out of the native Linux console command performance wise and it’s dirt cheap, supports regex, etc) you’ll find yourself making mass site-wide edits in the blink of an eye because even your white-space is uniformly the same strict approach.

    Should you heed my advice use a AFR (Advanced Find and Replace) to search for (but not replace) all instances of “mysql_query” and correct the formatting of everything you’ve written. Mix in a little AJAX notifications and you can see the errors instantly while you’re still in the browser without a single alt-tab. That’s how I roll.

    …and of course doing this will make your debugging much easier. This isn’t a fish, this is fishing and I hope it helps.

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

Sidebar

Related Questions

I am new to php and trying to write a login function. Bit stuck
I'm pretty new to XQuery and I'm trying to write an example function that
I am trying to write a new record to two database tables which are
I'm new to databases and am trying to add a new record using SQL.
I am trying to write a dynamic form using PHP. I'd like to have
I am trying to get hibernate to write new objects each time I do
I'm new to C# and trying to write a simple GUI Unit Test with
I'm new to cakephp and trying to write a simple app with it, however
I am new stored procedures and trying to write a procedure to duplicate user(by
I'm new to Pascal and I am trying to write a simple program, but

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.