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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:28:23+00:00 2026-06-16T11:28:23+00:00

I need to take an input (date) from a form in a php file,

  • 0

I need to take an input (date) from a form in a php file, and use the date variable to select data from a mysql database and return an array in the same php file without refreshing the page. Right now, I have 3 files: index.php, global.js, and date.php

index.php takes an input (a date, in this case)

Date: <input type="text" id="date">
  <input type="submit" id="date-submit" value="Submit">
  <div id="date-data"></div>
  <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script src="js/global.js"></script>

global.js listens for a click on the submit button and posts the input (date) to date.php

$('input#date-submit').on('click', function() {
    var date = $('input#date').val();
    $.post('../ajax/date.php', {date: date}, function(data) {
        $('div#date-data').html(data);
        alert(data);
    });

});

date.php takes the date and queries the mysql database to return an array. This array needs to be passed back to index.php but I can’t figure out how to do it.

<?php 

$con = mysql_connect('localhost', 'root', 'pass');
mysql_select_db('gymflow', $con);
  $date = $_POST['date'];
  $query = mysql_query("SELECT * FROM table WHERE `date` = $date");
    $values = array();

  while ($row = mysql_fetch_array($query))
  {
    $values[] = $row['utilization'];
  }
echo json_encode($values);

?>

Ideally, I need to be able to have the $values variable from date.php passed to a $values variable in index.php

There must be an easier way to do this…

  • 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-16T11:28:31+00:00Added an answer on June 16, 2026 at 11:28 am

    The purpose of your AJAX call is to not refresh index.php, and instead deliver the result of data.php straight into the first page. You can modify the DOM via the javascript callback, and should make other database-requests in data.php. There is no purpose in letting index.php aware of the output of data.php, simply because when the Javascript call is made, your first page has already been processed and sent to the client and possibly already rendered in the browser window.

    If you need to know the input value in subsequent requests to index.php you may store in the value in the user’s session.

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

Sidebar

Related Questions

I have a homework assignment where I need to take input from a file
I have an executable that I need to take input from a .wav file
In my project i need to take an expression input from user as string
I am working on a small project: I need to take the input from
In my app I have programmable keyboard and I need to take input from
I need to take input from the user a floating point array and then
Hello I am trying to take a date input from jquery UI and process
I need to take an input from a WYSIWYG and break it down to
In my application, I need to take input from the user for a column
In C, suppose I need to take input from a string int num,cost; char

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.