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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:47:23+00:00 2026-05-21T05:47:23+00:00

I am having issues with filling in a form and pressing submit to send

  • 0

I am having issues with filling in a form and pressing submit to send my information to a database. The problem is that my page refreshes even though I am using AJAX to stay on the same page and receive a reply in “show_label”.

I have tested to see if addCustomerFunc gets called by changing the show_label, and it does change! But still refreshes and I lose the message after it refreshes. I was hoping if someone could catch my mistake(s).

This is in my customer.php

<script type="text/javascript">

function addCustomerFunc(add_LN,add_FN,add_PN,add_DOB)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("show_label").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("POST","addCustomer.php",true);
xmlhttp.send("add_LN="+add_LN+"&add_FN="+add_FN+"&add_PN="+add_PN+"&add_DOB="+add_DOB);
}
</script>

    <p>Add New Customer:</p>
    <div align="center">
      <table width="337" border="1">
        <tr>
          <td width="154"><p>Last Name:</p>
          <p>First Name:</p>
          <p>Phone Number:</p>
          <p>Date of Birth:</p>
          <p>&nbsp;</p></td>
          <td width="167"><p align="center">
            <form>
                <input type="text" name="add_LN" id="add_LN" />
                <br/><br/>
                <input type="text" name="add_FN" id="add_FN" />
                <br /><br />
                <input type="text" name="add_PN" id="add_PN" />
                <br /><br />
                <input type="text" name="add_DOB" id="add_DOB" />
                <br /><br />
                <input type="submit" name="add_Customer" id="New_Customer_Form" value="Add Customer" onClick="addCustomerFunc(add_LN, add_FN, add_PN, add_DOB)"/>
            </form>
            <div id="show_label"/>
          </p>
          </td>
        </tr>
      </table>
      </div>

addCustomer.php

<?php
$username="****";
$password="****";
$database="****";

$lastName=$_POST['add_LN'];
$firstName=$_POST['add_FN'];
$phone=$_POST['add_PN'];
$dob=$_POST['add_DOB'];
//$membership==$_POST['membership'];

mysql_connect("******",$username,$password);

@mysql_select_db($database) or die( "Unable to select database");


$query = "INSERT INTO customer (last_name, first_name, phone_no, date_of_birth, membership) VALUES ('$lastName', '$firstName', '$phone', '$dob', 'T')";

if (mysql_query($query)){
    echo "Thanks";
} else 
{
    echo "Failed to insert customer into database";
}

mysql_close();

?>

Also, am I passing the variables correctly in addCustomerFunc?
Am I using “Post” correctly?

Thanks!

Edit: I am now having issues with passing the variables because it says:
Undefined index: add_LN in C:\Users\ej\Desktop\cpsc471\presentation\addCustomer.php
It adds blanks to my database though.

  • 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-21T05:47:24+00:00Added an answer on May 21, 2026 at 5:47 am

    Since you are using a form, you need to make sure that you capture the submit event before it is allowed to proceed and refresh the page.

    This should do the trick. (notice the return false)

    <input type="submit" name="add_Customer" id="New_Customer_Form" value="Add Customer" onClick="addCustomerFunc(add_LN, add_FN, add_PN, add_DOB); return false;"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having issues attaching a Database and full text catalog from server A to server
I'm having issues with over-lapping tables using iTextSharp. I have multiple tables(from gridviews) that
im having issues with the following interface and a class: public interface IRelated {
I'm having issues with XMLHttpRequest downloading progressive data. I get a state 2 and
I'm having issues when I take screenshots. This is my test code. import java.awt.Robot;
I've been working on a frequency detection application for iOS and I'm having an
I want to implement readmore/less feature. i.e I will be having html content and
So imagine that you have a table of Products (ID int, Name nvarchar(200)) ,
A brief background: I'm working on a web-based drawing application and need to draw
I'm relatively new to Flex however needed to take over maintenance and development of

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.