3

I am trying to delete a specific entry in my MYSQL Database.

Database: PhotoID, IDCount, UserID.

This is my code for deleting a photo depending on the ID.

function delete($IdPhoto) {

$result = query("DELETE from photos WHERE IdPhoto='%d'", $IdPhoto);
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');
}
}

This is paired with an iOS Application that grabs the current photos ID at all times. When a button is pressed, the delete function in the API will trigger. This doesn't seem to work though.

The following query works (specific ID):

    $result = query("DELETE from photos WHERE IdPhoto=10");

Any help would be appreciated. The goal is to delete the photo depending on the $IdPhoto we grab in the iOS Application.

4

4 回答 4

1

did you tried this :

     $result = mysql_query("DELETE from photos WHERE IdPhoto='$IdPhoto'  ");

you should use mysql_query

于 2013-07-19T15:39:37.090 回答
1

Try this:

$result = query("DELETE from photos WHERE IdPhoto={$IdPhoto}");
于 2013-07-19T15:42:29.087 回答
1

This

..IdPhoto='%d'

should be

..IdPhoto=%d

Since a int value shouldn't be surrounded by quotes

于 2013-07-19T15:56:40.170 回答
0

The "=" will only compare two int values or double values. Make sure you are comparing the type int. Thus your delete function should pass an int, otherwise you might need a function like getIntvalue() to extract the int value.

于 2013-07-19T18:30:30.593 回答