I am currently having trouble deleted a photo from my database after a user uploads it.
This is my index file.
case "delete":
delete((int)$_POST['IdPhoto']);
break;
This is my API file (Trying to delete photo with specific ID for testing):
function delete($IdPhoto) {
$result = query("DELETE from photos WHERE IdPhoto='28'");
if (!$result['error']) {
// if no error occured, print out the JSON data of the
// fetched photo data
print json_encode($result);
} else {
//there was an error, print out to the iPhone app
errorJson('Photo stream is broken');
}
}
That works perfectly. How would I do it for any ID though or a specific one that I would grab through my iOS application?
The application grabs IdPhoto, ID, Title automatically when it loads the image. I just need the proper query to determine it by the specific ID.
If it helps, this is how I load images:
// load the last 50 photos from the "photos" table, also join the "login" so that you can fetch the
// usernames of the photos' authors
$result = query("SELECT IdPhoto, title, l.IdUser, username FROM photos p JOIN login l ON (l.IdUser = p.IdUser) ORDER BY IdPhoto DESC LIMIT 50");
DELETE FROM photos WHERE PhotoData = '$photoData' AND Title='$title'
PD:insert_id don't return you the Id of DELETE... you need select before the id ;) (Almost, is better delete with id, than from title / photodata ;)) – Eleazan Jul 19 at 14:41(int)
is not an alternative to proper SQL escaping. – tadman Jul 19 at 15:23