Hey...
so I have an AJAX function which just calls my php code. I have it set up to display the returned text of the php page, just for debugging purposes (will get rid of this in the future).
That works, I have put alert()'s in everywhere possible to see what is going on at different parts.
The problem is my PHP code...it jsut for some reason doesnt return anything...I have echo's scattered through out, and at one point deleted everything inside it and set to be just "echo "test";" and still didnt return anything...
might just be something silly im missing...very well could be, cause im sick and my head isnt screwed on right right now 😛
Anyways here is my code:
call to ajax:
<div class="song_download" id="serpentine_offering" onclick="update_hit(this.id,'ajax_song_update.php')">blah</div>
AJAX code:
function update_hit(song,url){
var pageRequest = false
if (window.XMLHttpRequest) {//all browsers except IE
pageRequest = new XMLHttpRequest()
}
else if (window.ActiveXObject){ //Internet Explorer
try {
pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
}catch (e) {
try{
pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
}catch (e){}
}
}
else return false
pageRequest.onreadystatechange=function() {
if (pageRequest.readyState == 4) {
alertDone = alert(pageRequest.responseText);
}
}//end function
if (url) {//if data is not null. This is where the data is sent to the php file, using POST
var sendData = 'song=' + song;//the ids which will be sent to php. also it will tell the query that it is from the time
pageRequest.open('POST',url,true);
pageRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
pageRequest.send(sendData);
}
else {
pageRequest.open('GET',url,true)
pageRequest.send(null)
alert("rock");
}
}//end UpdateApproved()
PHP code:
<?php
include('scimitar_connect.php'); //logging in to sql server
$songName = $_POST['songName'];
$query = "SELECT * FROM `tblsongDownloads WHERE songName = '$songName'";
if(mysql_query($query)){
$count = mysql_result($result,0,'songCount');
$id = mysql_result($result,0,'DLKey');
$count = $count + 1;
$query = "UPDATE `tblSongDownloads SET songCount = '$count' WHERE DLKey = '$id'";
mysql_query($query);
echo("in if");
}else{
$query = "INSERT INTO `tblSongDownloads` VALUES('','$songName','1')";
mysql_query($query) or die("ERROR:: ".mysql_error());
echo("in else");
}
?>
Anyone see the error?
ps. all this code is supposed to do is get a value from my db, increment it by 1 and save it again..
thanks!
Paul