I have a form with a button and I'm trying to connect with the db via ajax.
form:
- Code: Select all
<form method="get" >
<input type="button" name="submit" onClick="deleteSales()" value="Delete all" class="button">
</form>
the Ajax:
- Code: Select all
<script language="Javascript" type="text/javascript">
<!--
var xmlHttp = false;
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
function deleteSales(){
var url = "../application/delete-sales.php";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = updateDeleted;
}
function updateDeleted(){
if(xmlHttp.readyState == 4){
document.getElementById("messageD").innerHTML = xmlHttp.responseText;
}
}
//-->
</script>
the PHP:
- Code: Select all
<?php require_once("../inc.php");
echo " script arrived here!";
$con = mysql_connect('localhost','root','password') or die ("Could not connect!");
mysql_select_db('quickbeamdb');
//check Session user
if(isset($_SESSION['admin_user'])){
$profit = "profit";
$totals = "totals";
}else if(isset($_SESSION['regis_user'])){
$profit = $_SESSION['regis_user']."_profit";
$totals = $_SESSION['regis_user']."_totals";
}
$sql = "TRUNCATE TABLE $profit" ;
$result = mysql_query($sql);
$sql = "UPDATE $totals SET totalexpense ='0',
totalsales ='0',
totalprofit = '0',
date = NOW() WHERE id='1'" ;
$result = mysql_query($sql);
if(isset($_SESSION['profit_total'])){
unset($_SESSION['profit_total']);
}
if(isset($_SESSION['expenses_total'])){
unset($_SESSION['expenses_total']);
}
if(isset($_SESSION['sales_total'])){
unset($_SESSION['sales_total']);
}
echo "All items have been deleted from table!";
mysql_close($con);
?>
Nothing happens. I tried to display a text when the ajax function(deleteSales) is called, and the text displays, so the script goes to ajax but never to php.
Any help will be much appreciated,
Mike


