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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:50:57+00:00 2026-06-10T21:50:57+00:00

I have two database tables, guestlist and attendance On one HTML page, I have

  • 0

I have two database tables, guestlist and attendance

On one HTML page, I have a window.onload script that I want to check the guestlist via AJAX. If the firstname AND lastname in the url query appear in the guestlist table, then load the page. If not, load an error message.

When the page is properly loaded, the firstname and lastname are pre-populated in two input fields. The user completes the rest of the form and clicks submit, inserting their firstname and lastname into the attendance table.

If the firstname and lastname already appear in the attendance table, load an error message. If the firstname AND lastname to not appear in the attendance table, submit the form information to the attendance table.

When it comes to Ajax, I am not the bright bulb in the pack. This is the code I currently have:

HTML

<body>
<div id="formDiv">
<form id="partyForm" name="party" action="party_insert" method="post">
<h1>Welcome to The Party</h1>
    <input name="first_name" id="firstname" class="input" type="text" maxlength="99" placeholder="First Name"><br/>
    <input name="last_name" id="lastname" class="input" type="text" maxlength="99" placeholder="Last Name"><br/>
    <input name="costume" id="costume" class="input" type="text" maxlength="999" placeholder="What are you supposed to be?"><br/>
    <div id="buttonDiv">
        <a class="button" id="submit" style="cursor:pointer;">SUBMIT</a>
    </div>
</form>
</div>

<script>
window.onload = function () {
    var fname_init = decodeURIComponent(getUrlVars()["fname"]);
    var lname_init = decodeURIComponent(getUrlVars()["lname"]);

    if(fname_init !== "undefined" && lname_init !== "undefined"){
        var newString = 'fname='+encodeURIComponent(fname_init)+'&lname='+encodeURIComponent(lname_init);
        $.ajax({
            type: "GET",
            url: "guestList.php",
            data: newString,
            success: function(){
                alert("ON THE LIST");
                $('#firstname').val(fname_init);
                $('#lastname').val(lname_init);
            },
            error: function(){
                alert("NOT ON THE LIST");
                window.location = 'error1.html?fname='+encodeURIComponent(fname_init)+'lname='+encodeURIComponent(lname_init);
            }
        })
    }
}

$("#submit").click(function() {
    validate();
});

function submit(){
    var fname = $("#firstname").val();
    var lname = $("#lastname").val();
    var cost = $("#costume").val();
    var dataString = 'fname='+encodeURIComponent(fname)+'&lname='+encodeURIComponent(lname)+'&cost='+encodeURIComponent(cost);
    $.ajax({  
        type: "POST",  
        url: "partyEntry.php",  
        data: dataString,  
        success: function() {  
            alert("ENJOY THE PARTY");
            clearForms();
        }
    });
}

function validate(){
    if ($("#firstname").val() == ""){
        alert("Please Enter your First Name");
    } else {
        if ($("#lastname").val() == ""){
            alert("Please Enter your Last Name");
        }else{
            if ($("#costume").val() == ""){
                alert("You have to have a costume to be eligible for this raffle");
            }else{
                submit();
            }
        }
    }
}

function clearForms() {
    $('#partyForm')[0].reset();

}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

</script>
</body>

guestList.php

<?php

    $host = "localhost";
    $user = "root";
    $password = "";
    $database = "party";

    $link = mysql_connect($host, $user, $password);
    mysql_select_db($database);

    //SURVEY INFORMATION
    $fname = mysql_real_escape_string($_REQUEST['fname']);
    $lname = mysql_real_escape_string($_REQUEST['lname']);

    $checkClient  = "SELECT * FROM guestlist WHERE first_name = ".$fname." AND last_name = ".$lname;
    mysql_query($checkClient) or die(mysql_error());

    mysql_close($link);

?>

partyEntry.php

<?php

    $host = "localhost";
    $user = "root";
    $password = "";
    $database = "party";

    $link = mysql_connect($host, $user, $password);
    mysql_select_db($database);

    //SURVEY INFORMATION
    $fname = mysql_real_escape_string($_REQUEST['fname']);
    $lname = mysql_real_escape_string($_REQUEST['lname']);
    $cost = mysql_real_escape_string($_REQUEST['cost']);

    $addClient  = "INSERT INTO attendance (first_name, last_name, costume) VALUES ('$fname','$lname', '$cost')";
    mysql_query($addClient) or die(mysql_error());

    mysql_close($link);

?>

The error I am getting is that even though a name is not on the guestlist, it will still show that they are ON THE LIST. So I must be doing something wrong in the Ajax call to guestlist.php, but I have no idea what. I also am having problems scripting out an ajax call to check if the guest has already been put into the attendance table.

  • 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-10T21:50:58+00:00Added an answer on June 10, 2026 at 9:50 pm

    Like I said in my comment you will have to return a value from the guestList.php, something like this should work:

    $checkClient  = "SELECT * FROM guestlist 
                     WHERE first_name = ".$fname." AND 
                           last_name = ".$lname;
    $result = mysql_query($checkClient);
    $count = mysql_num_rows($result);
    mysql_close($link);
    // output 1 or 0 stating if the user is on the list or not
    echo ($count ? 1 : 0);
    exit();
    

    Then in your ajax callback you would do a check like:

    success:function(e) {
       alert((e == 1 ? "User is on list" : "User isn't on list"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two database tables. One table stores data for a commitment that a
I have a SQL script that is setting up two database tables with their
I have a database two tables and a linking table that I need a
I have two tables in my database schema that represent an entity having a
I have two tables in my database that look like that: Customer: C_ID city
I have two tables in my MySQL database, one is a library of all
I have two database tables, one for Users of a web site, containing the
I have two database tables that have a many to many relationship: People and
I have two database tables that represent lists of items that belong to parent
I have two MySQL database tables that are meant to hold data for eshop

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.