Hi,
I'm designing a web page that has 6 drop down html form inputs (d, m, y, d, m, y) for pulling records from a mysql database depending on users input of a range of dates. I'm trying to use an Ajax script that will hopefully, on submit of form, show the selected records below the html form without refreshing the page, this works great apart from the fact that it is formatting the date submitted wrongly and php/mysql isnt liking it. I know the php date formatting is right because if i submit the form directly to the PHP page with any ajax, the dates are right and it does select records between the two inputted dates!
Does anyone know why it would do this or how to correct it so i can use the ajax to show the records without a page refresh?
AJAX FILE (relevant ajax code is the first function that goes to dates.php)
// AJAX REQUEST
function httpRequest(){
var httpRequest = null;
try { httpRequest = new XMLHttpRequest(); }
catch(e){
try{httpRequest = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){httpRequest = new ActiveXObject("Microsoft.XMLHTTP");}
}
return httpRequest;
}
var t;
function ajaxFunction(){
var http_request = httpRequest();
var dateresult = document.getElementById('dateresult');
var url = "dates.php";
http_request.open("POST", url, true);
http_request.onreadystatechange = function(){
if(http_request.readyState == 4){
dateresult.innerHTML = http_request.responseText;
}
}
http_request.send(null);
t = setTimeout(ajaxFunction, 1000);
}
function load_data1(){
var http_request = httpRequest();
var object_area1 = document.getElementById('tablecontainer1');
var url = "ajaxphp.php";
http_request.open("POST", url, true);
http_request.onreadystatechange = function(){
if(http_request.readyState == 4){
object_area1.innerHTML = http_request.responseText;
}
}
http_request.send(null);
t = setTimeout(load_data1, 1000);
}
document.onLoad = load_data1();
PHP FILE
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "test";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die("Cannot connect to mysql server");
mysql_select_db($dbname) or die("Cannot select database");
if($conn){
$datef = (date("Y-m-d",mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year'])));
$datel = (date("Y-m-d",mktime(0, 0, 0, $_POST['month1'], $_POST['day1'], $_POST['year1'])));
echo $datef;
echo $datel;
$result = mysql_query("SELECT * FROM mashwash1 WHERE t_stamp BETWEEN '".$datef."' AND '".$datel."'");
echo "<table>
<tr>
<th>F18:0</a></th>
<th>Timestamp</a></th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['F18_0'] . "</td>";
echo "<td>" . $row['t_stamp'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</br>";
}
?>
HTML FORM
<form method="POST" action="dates.php">
<select name="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="15">15</option>
</select>
<select name="month">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select name="year">
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
</select>
<select name="day1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="15">15</option>
</select>
<select name="month1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="6">6</option>
</select>
<select name="year1">
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
</select>
<input type="button" value="Submit"
onClick="ajaxFunction()" />
</form>
<div id="dateresult">
</div>