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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:04:10+00:00 2026-06-17T17:04:10+00:00

been trying to figure out how to echo a query result to a textbox

  • 0

been trying to figure out how to echo a query result to a textbox in a div. I have a form (see below) and it does place the result in a textbox as I want but is not echoing back to the div (which is called ‘content’). I’ve updated the code for my HTML here after some edits:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<form id="search" method="post" action="rating.php">Miles <input name="miles" id="miles" type="text" /> <input name="search1" id="search1" class="btnButton" value="Search" type="submit" /></form>
<div id="content"></div>
<script type="text/javasript" src="jquery-1.9.0.min.js"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function(){

//jquery click event
$("#search").on("submit", function(e){

   //disable default form submit postpage
   e.preventDefault();

   //make ajax call to the search.php parsing the search textbox value as query string
   $.get("rating.php?miles="+$("#miles").val(), function(result){

        //Result will be dumped in the div
        $("#content").html(result);

       });

   });

});
// ]]></script>
</body>
</html>

The value of miles is now passed to rating.php where I want it to do a query and then format the result in a textbox format that is displayed in the div:

<?php
$hostname = 'somehost.com';
$username = 'ratetable';
$password = 'mypassword';

$miles = (int) $_POST['miles'];

try 
{
$db = new PDO("mysql:host=$hostname;dbname=ratetable", $username, $password);

foreach($db->query("SELECT * FROM rates WHERE mileage<={$miles} ORDER BY mileage DESC LIMIT 1") as $row) {
 $result= "<input type='text' name='answer' value='" . $row['ratepermile'] . "'>'";
 echo $result;

   }
}         

catch (PDOException $e) {
  echo $e->getMessage();
  throw($e); 
}
?>

The result is formatted the way I want, except that it is not being echoed back to the script and placed where the result should be. Is there a way I can use div tags or otherwise ensure it’s going to a specific div?

Thank you for looking.

  • 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-17T17:04:12+00:00Added an answer on June 17, 2026 at 5:04 pm

    First thing comes to mind: you’re not including the jQuery library anywhere in the example.
    Also, notice the comma on the following line should be a dot:

    e,preventDefault();

    If that’s not the problem but just the result of hasty copy / pasting, are sure that your $.get() request is giving you any output at all?

    You probably also want to change the following:

    $(“#search”).live(“click”, function(e){

    to something like:

    $(“#search”).on(“submit”, function(e){

    because the reference of #search is pointing to your form-tag rather than to a button

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

Sidebar

Related Questions

I have been trying to figure out why I am getting this problem and
I have been trying to figure out how to read paragraph content which exists
I have been trying to figure out how to open a file from the
I have been trying to figure out a solution but nothing has really presented
I have been trying to figure out a way to tag several methods from
I have been trying hard to figure out the best solution to a pagination
I have been trying to figure out a way to load something in PHP
I have been trying to figure out this issue I am having with PHP
I have been trying to figure out how to grab contents from an S3
I have been struggling trying to figure out this mindbody API for a while

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.