Problem concerning a PDO statement in a simple webservice setting

Hi all.

I’m having to write a simple webservice that manages a shopping list. When online, it should use direct PDO statements, when offline, it stores the items via javascript and localStorage.

So far, I get everything to work (adding items works, showing the list works, both off- and online), but somehow, my delete function doesn’t propagate to the database.

Here is how I handle the client-side:

[code]function loescheArtikel(artikelText){
var loeschenListe = localStorage.getItem(“loeschenListe”);
var deleteRequest = null;

if (navigator.onLine) {
	if (loeschenListe == null) loeschenListe = '"'+artikelText+'"'
	else loeschenListe = loeschenListe+' OR "'+artikelText+'"';
	
	cleanListe = loeschenListe.replace(/\s/g, "%20");
	deleteRequest = new XMLHttpRequest();
	deleteRequest.onreadystatechange = function (){
				if (deleteRequest.readyState == 4) console.log(deleteRequest.responseText);
	};
	deleteRequest.open('DELETE','Ue10Service.php/'+cleanListe,true);
	deleteRequest.send(null);
} else {
	var loeschenListe = localStorage.getItem("loeschenListe");
	if (loeschenListe == null){
		localStorage.setItem("loeschenListe", '"'+artikelText+'"');
	} else {
		localStorage.setItem("loeschenListe", loeschenListe+' OR "'+artikelText+'"');
	}
	console.log(artikelText+" zur LoeschenListe hinzugefügt");
}

}[/code]

and the server-side:

[php]if (isset($_SERVER[‘PATH_INFO’])){
$path = explode("/", $_SERVER[‘PATH_INFO’]);
$loeschenListe = urldecode($path[1]);
try{
$stmt = $db->prepare(‘DELETE FROM liste WHERE beschreibung LIKE :loeschenListe’);
$stmt->bindParam(’:loeschenListe’, $loeschenListe);
$stmt->execute();
header(“HTTP/1.0 200 OK”);
echo "Deleted ".$loeschenListe;
} catch (PDOException $e){
header (“HTTP/1.0 500 INTERNAL SERVER ERROR”);
echo $e->getMessage();
return;
}
}
}[/php]

When I execute the loescheArtikel function, I always get to the point where I get a “200 OK” header back from the server, and it says that I successfully deleted “item” (echo "Deleted ".$loeschenListe;). The problem is, the statement does not propagate to the database, and I get no error whatsoever. Anyone got any ideas why that is?

Sponsor our Newsletter | Privacy Policy | Terms of Service