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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:10:30+00:00 2026-06-02T19:10:30+00:00

I am attempting to send different error messages back to an HTML DIV depending

  • 0

I am attempting to send different error messages back to an HTML DIV depending on the PHP outcome. I have searched through here and other place but have been unable to locate an answer that seems to work for my situation… hopefully someone else can help me with this.

My HTML page includes a form that a user is asked to enter a reservation ID # (unique), once the user does this and presses “Search Reservation” a Jquery script is called to send the ID to a PHP script via AJAX. The Data is returned and then is populated into a form using a jquery plugin called, “populate”.

Here is the script:

<script type="text/javascript">
$(document).ready(function(){
    resetForms('reservation');
    $('#form-reservation').submit(function(event){ 
        event.preventDefault();  //the page will no longer refresh on form submit.
    var resCheck = $(this).find('input[class="reservationid"]').val(); //now we have the reservation ID, let's perform our check.
        $.ajax({ 
            url: 'inc/searchres.php', 
            type: 'POST',
            data: 'resid='+resCheck, 
            success: function(data){  //data is all the info being returned from the php file 
                resetForms('reservation');  //clear forms
                $('#reservation-id').val(resCheck);  //add res ID back into text box
                var jsonData = $.parseJSON(data);  //parse returned JSON data so we can use it like data.name, data.whatever 
                $("#res-message").html('<a>Reservation ID Located, Information is displayed below</a>');
                $('#json-reservation').populate({personal_first_name:jsonData['element_1_1'],personal_last_name:jsonData['element_1_2'],personal_phone_1:jsonData['element_7'],personal_email:jsonData['element_2'],reservation_status:jsonData['ADD THIS CELL'],reservation_date:jsonData['element_3'],reservation_time:jsonData['element_4'],reservation_party:jsonData['element_5'],reservation_special_request:jsonData['element_6'],reservation_using_coupon:jsonData['element_9'],reservation_coupon_code:jsonData['element_10'],reservation_status:jsonData['element_11']});
            },
            error: function(){
                $("#res-message").html('<a>There was an error with your request</a>');
            }
        });
    });
});
</script>

This was called from the following form (which also includes the DIV in which I would like to populate my error messages, res-message):

<form name="form_reservation" id="form-reservation">
                    <div style="padding:10px 20px 10px 10px;">
                    <label for="reservation-id">Reservation ID</label>
                        <input name="reservation_id" id="reservation-id" class="reservationid" style="width:120px !important"/>
                        <div class="res_message" id="res-message">&nbsp;</div>
                        <input type="submit" class="button" value="Search Reservation" style="width:150px !important; margin:10px 0px 0px 5px;"/>
                        <input type="button" class="button" value="Clear" style="width:150px !important; margin:10px 0px 0px 5px;" onclick="resetForms('reservation')" />
                    </div>
                </form>

The form that is populated should not be important for this question. Finally the PHP looks like such:

<?php
    include('config-searchres.php');

    $term = $_POST['resid'];
    $sql = mysql_query("SELECT * FROM ap_form_8 WHERE id = '$term'"); //select first name (element_1_1) from form #8
    //$sql = mysql_query("SELECT * FROM ap_form_8 WHERE element_12 = '$term'");  //real selector will look for unique number that has not been added to table yet

    if ($row = mysql_fetch_array($sql)){  //if reservation number exists
        if ($row['element_11'] != 'Cancelled'){  //if reservation has not already been cancelled
            if (strtotime($row['element_3']) >= strtotime(date("Y-m-d"))){  //if reservation has not already passed date
                echo json_encode($row);
            }
            else  //Reservation already passed (old reservation)
            {
                echo $error = "Passed"; 
                //echo 'passed';
            }
        }
        else  //Reservation already cancelled
        {
            echo 'cancelled';
        }
    }
    else  //Reservation not found
    {
        echo 'not found';
    }
    mysql_close();
?>

I know next to nothing about PHP, but I do know that this script seems to work for populating my tables… just not displaying errors for other situations. 3 different errors, ‘passed’, ‘cancelled’, and ‘not found’ need to be passed back during their respective situations. Anyone have an idea?

  • 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-02T19:10:32+00:00Added an answer on June 2, 2026 at 7:10 pm

    The quick and dirty solution is to test the returned result to see if it is a string or an array. On your javascript:

                    (...)
                    var jsonData = $.parseJSON(data);  //parse returned JSON data so we can use it like data.name, data.whatever
                    if (typeof(jsonData)=='object'&&(jsonData instanceof Array)) {
                        // jsonData is an array, populate success div
                        $("#res-message").html('<a>Reservation ID Located, Information is displayed below</a>');
                        $('#json-reservation').populate({personal_first_name:jsonData['element_1_1'],personal_last_name:jsonData['element_1_2'],personal_phone_1:jsonData['element_7'],personal_email:jsonData['element_2'],reservation_status:jsonData['ADD THIS CELL'],reservation_date:jsonData['element_3'],reservation_time:jsonData['element_4'],reservation_party:jsonData['element_5'],reservation_special_request:jsonData['element_6'],reservation_using_coupon:jsonData['element_9'],reservation_coupon_code:jsonData['element_10'],reservation_status:jsonData['element_11']});
    
                    } else {
                        // jsonData is a simple string, so PHP returned an error. populate error div
                        $("#res-message").html('<a>There was an error with your request</a>');
                    }
                    (...)
    

    Naturally, when handling the error, you can switch on jsonData contents to provide a specific error message if needed.

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

Sidebar

Related Questions

I'm attempting to send a piece of data through jQuery .ajax() to a PHP
I am attempting to send and receive messages through NSNotificationCenter in Objective-C. However, I
I am attempting to send html data in a question form from my php
I am attempting to send mail through my gmail account from a Dedicated Godaddy
I have a HTTP GET request that I am attempting to send. I tried
I am attempting to send data back to my objective c program from javascript.
I'm attempting to send HTML formatted emails using C# 3 via Outlook.MailItem Outlook.MailItem objMail
I am attempting to send a message via sockets from VBA. I have made
I'm attempting to send an email using the CakePHP SwiftMailer component I found here:
While attempting to send a message for a queue through the BeginSend call seem

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.