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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:31:55+00:00 2026-06-16T16:31:55+00:00

I am trying to input name and phone in form and get data from

  • 0

I am trying to input name and phone in form and get data from mysql based on input values. When I run query by on click function the browser displays my php and query but instead of values from database it displays ‘object HTMLInputElement’.

I must be missing something in my script but can’t figure out what it is.
Can anybody tell me when I submit this ajax/mysql why the value is not being displayed. See code below and hanks for your help…

HTML and SCRIPT

<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script language="javascript" type="text/javascript">

function ajaxFunction(){
var ajaxRequest;  

try{

    ajaxRequest = new XMLHttpRequest();
} catch (e){

    try{
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e){

            alert("Your browser broke!");
            return false;
        }
    }
}

ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
        var ajaxDisplay = document.getElementById('ajaxDiv');
        ajaxDisplay.innerHTML = ajaxRequest.responseText;
    }
}
var age = document.getElementById('lname').value;
var queryString = "?lname=" + lname + "&phone=" + phone ;
ajaxRequest.open("GET", "find.php" + queryString, true);
ajaxRequest.send(null); 
}

</script>
<form name='myForm'>
Last Name: <input type='text' id='lname' />
Phone: <input type='text' id='phone' />
<input type='button' onclick='ajaxFunction()' value='Query MySQL' />
</form>
<div id='ajaxDiv'>Your result will display here</div>
</body>
</html>

PHP

$inputedname = $_GET['lname'];
$inputedphone = $_GET['phone'];

$inputedname = mysql_real_escape_string($inputedname);
$inputedphone = mysql_real_escape_string($inputedphone);

$query = "SELECT FirstName, Phone FROM ClientInfo WHERE LastName = '$inputedname' AND Phone = '$inputedphone'";

$qry_result = mysql_query($query) or die(mysql_error());


$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Name</th>";
$display_string .= "<th>Phone</th>";
$display_string .= "</tr>";


while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr>";
$display_string .= "<td>$row[FirstName]</td>";
$display_string .= "<td>$row[Phone]</td>";
$display_string .= "</tr>";

}
echo "Query: " . $query . "<br />";
$display_string .= "</table>";
echo $display_string;

In Browser

enter image description here

  • 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-16T16:31:57+00:00Added an answer on June 16, 2026 at 4:31 pm

    That’s because you never defined the variables lname and phone in your var queryString = "?lname=" + lname + "&phone=" + phone ; line. Therefore, browsers generate variables from your input element IDs. When you use a DOM element in string concatenation, its toString() is called and it outputs [object HTMLInputElement]. That’s a feature that IE gave us from the early days and other browsers copied to be IE compatible. It’s a feature you should not use.

    The following code will fix your problem.

    var lname = document.getElementById('lname').value;
    var phone = document.getElementById('phone').value;
    var queryString = "?lname=" + lname + "&phone=" + phone ;
    ajaxRequest.open("GET", "find.php" + queryString, true);
    

    As an aside, to prevent SQL injection, you should use prepared statements instead of http://php.net/manual/en/function.mysql-real-escape-string.php which is deprecated

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

Sidebar

Related Questions

I'm trying to insert values from a form and insert it onto a MySQL
I'm trying to get my name and trip input fields to line, but they're
I am trying to set the database name as the request input parameter from
I am trying to get the JQuery Token Input prepopulated. var assignUserJson=$('#assignUserJson').val(); console.log(assignUserJson); //[{id:1,name:Andrew},{id:3,name:John}]
I am trying to input data from a text file in C++. The text
I am trying to get a basic data validation working on a form for
Hi there I'm trying to input 3 integers from the keyboard and print rows
Using VB.NET with ASP.NET and and ms-access 2003 data, I'm trying to input data
I'm trying to add input boxes based on a number provided by the user.
I am trying to send an email message with data collected from an html

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.