Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Unhappy :: problems with delete record ajax script..

    Hi all,

    im quite enw to PHP so this may be the wrong way of doing things... it is deleting the record but then i get an apache error. if i then refresh the page the record has been deleted.

    this is for an intranet based system im writing:

    javascript...
    Code:
    function deleterecord(thetable, theid) {
    	xmlHttp=GetXmlHttpObject()
    	if (xmlHttp==null) {
    		alert ("Browser does not support HTTP Request")
    		return
    	}
    	
    	var params = "?theid=" + theid + "&thetable=" + thetable;
    	var url="_delete_record.php"
    	url=url+params;
    	xmlHttp.onreadystatechange=stateChanged
    	xmlHttp.open("GET",url,true)
    	xmlHttp.send(null)
    }
    
    function stateChanged() { 
    	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  { 
    		document.getElementById("theitems").innerHTML=xmlHttp.responseText;
    	} 
    }
    
    function GetXmlHttpObject() { 
    	var objXMLHttp=null
    	if (window.XMLHttpRequest) {
    		objXMLHttp=new XMLHttpRequest()
    	} 
    	else if (window.ActiveXObject) {
    		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    	}
    	return objXMLHttp
    }
    php _deleterecord.php ...

    Code:
    $query = "DELETE FROM $thetable WHERE id=$theid";
    mysql_query($query) or die('Error ,query failed');
    
    mysql_free_result($result);
    writes some data....
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    If you're getting an apache error it's not a problem with the javascript - especially if it's getting you to the delete entry php page. What is the error that apache gave you?
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    yeah, didnt think it was JS - just showing you my method in case its the wrong way to do it.

    i dont get an error in the error.log in the Apache2\logs folder...

    its windows Apache HTTP Server error - the ones where you send an error report.
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    bump...
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    ok, the line "mysql_free_result($result);" was causing the error!

    all working now!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •