0

I am trying to make a simple html page that takes info from two input fields and uses them to search a database. The two fields are just start and end datetime values.

I have this form which is automatically filled with today's date and 00:00 for the start time and 23:59 for the end time.

<!--field for start-->
<p>Start Date Time:</p>
<form action="" method="get">
<input type="text" name="date1" id="datetime1" /> 
<!--field for end-->
<p>End Date and Time:</p>
<input type="text" name="date2" id="datetime2" />
<!--button to modify search criteria-->
<button type="submit" id="f_trigger_b">Search</button>
</form>
</body>

I want to take the values in the two fields and use them to search an sql database using php. I have this section of code to get the information from the database in the header:

//<![CDATA[
//need to work with this so that info is passed
function load(timestart, timeend) {

//code here edited out for simplicity

    GDownloadUrl("genxmlphp.php", function(data) {

//code here edited out for simplicity

//]]>

How do I take the values from the two input fields and when the submit button is pressed, the load(time1, time2) is triggered and uses genxmlphp.php to search the database using the time1 and time2 values?

Stagleton
  • 1,060
  • 3
  • 11
  • 35

2 Answers2

0

Once the form is submitted, $_GET['date1'] and $_GET['date2'] will contain the form values. Although it might be better to switch the form method to post and use $_POST['date1'] and $_POST['date2'].

If you're not using prepared statements, when using these values in an SQL query escape them using mysql_real_escape_string() first (if you're using MySQL).

Michael
  • 11,912
  • 6
  • 49
  • 64
  • so would I change action = "" to action = load() and then within load() I can access the inputs with $_POST['date1'] or $_POST['date2']? – Stagleton Mar 30 '12 at 16:19
  • Sorry, I didn't look at the question properly. You want to do this with JavaScript rather than PHP? – Michael Mar 30 '12 at 16:23
  • I have a php file, genxmlphp.php, that returns all the results from the database I am sending a query to. I want to take the values from the form in html and use them as a filter in the php document. Once the values are passed to the php document, I'm fine. The process of taking the values from the form when the submit button is pressed and then using them in the 'load()' function is the gap I need to cross. – Stagleton Mar 30 '12 at 16:30
0

Sounds to me like you need something like this. This answer builds a SQL query from form inputs.

Community
  • 1
  • 1