Hi all ive some ajax posting to the same php file to submit the post data to the database, the form data is posting, it just isnt following on to the database :/ way it currently works is that ive a form that submits the form to the PHP then dependant on the resulting factors i put some ajax within a php if statement, which in turns posts back with the action confirm, this post is what i have got up to, i know it posts as the postdata is viewable within firedebug, the problem is, from there it refuses to post that data to my database. Thanks
AJAX in Question:
<script>
function AJAX(){
var override = confirm('<?=$customrule['misc']?> \nDo you wish to override this rule?');
if(override){
params= 'ajaxdate=<?=$date?>&ajaxenddate=<?=$enddate?>&ajaxmaxhols=<?=$maxhols?>&ajaxstafforjob=<?=$stafforjob?>&ajaxjobtitle=<?=addslashes($jobtitle)?>&ajaxname=<?=addslashes($name)?>&ajaxuserclient=<?=$userclient?>&ajaxdescription=<?=addslashes($_POST['description'])?>&ajaxportaluserid=<?=$portaluserid?>&action=confirm';
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject('MicrosoftXMLHTTP');
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status == 200) {}
};
xmlhttp.open('POST', 'cal_events.php', true);
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.setRequestHeader('Content-length', params.length);
xmlhttp.setRequestHeader('Connection', 'close');
xmlhttp.send(params);
} else { alert('Action Cancelled!');}}
AJAX();</script>
PHP:
if($_POST['action']==="confirm"){
$exception = true;
dbConnect();
dbOpenDatabase("****");
$date = $_POST['ajaxdate'];
$enddate = $_POST['ajaxenddate'];
$maxhols = $_POST['ajaxmaxhols'];
$stafforjob=$_POST['ajaxstafforjob'];
if($staffselected){
$daystobookoff = workingDays($date,$enddate);
$daysallowedoff = $maxhols;
$overbooked = $stafforjob - $maxhols;
}
if(count(workingDays($date,$enddate)) > $daysallowedoff && $exception=false){
echo "<script>alert('Trying to book more holidays than they are allowed');</script>";
} else {
echo "<script>alert('Calendar event added!');</script>";
foreach($daystobookoff as $day){
mysql_query("INSERT INTO cal_events (date,jobtitle,emp_id,clientid,description,userid) VALUES ('{$day}','{$_POST['ajaxjobtitle']}','".$_POST['ajaxname']."','{$_POST['ajaxuserclient']}','". $_POST['ajaxdescription'] . "','{$_POST['ajaxportaluserid']}')");
echo "<script>alert(\"INSERT INTO cal_events (date,jobtitle,emp_id,clientid,description,userid) VALUES ('{$_POST['day']}','{$_POST['jobtitle']}','".$_POST['name']."','{$_POST['userclient']}','". $_POST['description'] . "','{$_POST['portaluserid']}')\");</script>";
}
}
}