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?
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).