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 8743739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:43:49+00:00 2026-06-13T11:43:49+00:00

My PHP script is executing successfully and the records from the form are being

  • 0

My PHP script is executing successfully and the records from the form are being inserted into the Database, however, every time I press “submit form button” it gives me the alert “error” so my success function is not being executed and I don’t know why.

JAVASCRIPT

$(document).ready(function () {
    $(".button").click(function () {
        var dataString = 'name=' + name + '&email=' + email + '&comment=' + comment;
        $.ajax({
            type: 'POST',
            url: 'submit_form.php',
            dataType: 'json',

            data: dataString,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert('error');
                $('#message').removeClass().addClass('error')
                    .text('There was an error.').show(500);
            },
            success: function (data) {
                $('#contact_form').html("<div id='message'></div>");
                $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
                    .text(data.msg).show(500);
                $('#contact_form').hide();
            }
        });
        return false;
    });
});

PHP

//mysql connection string // 
$result = $mysqli->query("**fetch # of rows**");
$count  = $result->fetch_object()->Total;
$result->free();

echo "number of rows is $count";

if ($count > 10) {
    $return['error'] = true;
    $return['msg']   = 'Sorry The Queue is full';
}elseif ($stmt = $mysqli->prepare("**insert into db**")) {
    /* Bind our params */
    $stmt->bind_param("sss", $param1, $param2, $param3);

    /* Set our params */
    $param1 = $_POST["param1"];
    $param2 = $_POST["param2"];
    $param3 = $_POST["param3"];

    /* Execute the prepared Statement */
    $stmt->execute();
    $return['error'] = false;
    $return['msg']   = 'Thanks your comment was added!';

    /* Close the statement */
    $stmt->close();
} else {
    /* Error */
    printf("Prepared Statement Error: %s\n", $mysqli->error);
}

echo json_encode($return);
  • 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-13T11:43:50+00:00Added an answer on June 13, 2026 at 11:43 am

    The line:

    echo "number of rows is $count";
    

    will result in invalid JSON.

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

Sidebar

Related Questions

I have a PHP script that retrieves 200 lines from a file by executing
Is there a way to redirect output of an executing PHP script? Of course
My PHP script is displaying the wrong time. For eg. the time on my
I wrote a PHP script that retrieves values from a MySQL Query. I used
I am executing one php script, if data is less (approx 30K), it will
How do I get the URL of the currently executing PHP script? For example,
I make 7 get requests at the same time to one PHP script -
I need help with posting a value to a php script from a js
I have a php script that needs to run for quite some time. What
Possible Duplicate: Run a PHP CLI script from a webpage I have a problem

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.