| Author |
mysql DELETE syntax on 3.23.58
|
|
| Mark D. Smith 2006-04-25, 7:03 pm |
| Hi
i can INSERT and UPDATE but DELETE is not working
$sql = "DELETE FROM table WHERE ID='$ID'";
$sql_result = mysql_query($sql,$connection) or die ("Couldn't execute Delete
of row $ID.");
$ID is the primary key and i want to delete the entire row based on the
users selection.
Mark
| |
| J.O. Aho 2006-04-25, 7:03 pm |
| Mark D. Smith wrote:
> Hi
>
> i can INSERT and UPDATE but DELETE is not working
>
> $sql = "DELETE FROM table WHERE ID='$ID'";
> $sql_result = mysql_query($sql,$connection) or die ("Couldn't execute Delete
> of row $ID.");
>
> $ID is the primary key and i want to delete the entire row based on the
> users selection.
$sql="DELETE FROM table WHERE ID='$ID'";
if(!($del_res=mysql_query($sql))) {
$sql="SELECT ID FROM table WHERE ID='$ID'";
if($sel_res=mysql_query($sql)) {
if(mysql_num_rows($sel_res)) {
echo "Couldn't delete $ID\n";
} else {
echo "False positive result, there is no $ID in the table\n";
}
} else {
echo "There aren't any $ID in the table\n";
}
} else {
if($rows=mysql_affected_rows($del_res)) {
echo "Number of entries deleted: $rows\n";
} else {
echo "There wasn't anything to delete\n";
}
}
This should give you a better understanding why the delete failed.
//Aho
| |
| Mark D. Smith 2006-04-25, 7:03 pm |
| "J.O. Aho" <user@example.net> wrote in message
news:4b1ve0Fvh1iiU1@individual.net...
> Mark D. Smith wrote:
Delete[color=darkred]
>
>
> $sql="DELETE FROM table WHERE ID='$ID'";
>
> if(!($del_res=mysql_query($sql))) {
> $sql="SELECT ID FROM table WHERE ID='$ID'";
> if($sel_res=mysql_query($sql)) {
> if(mysql_num_rows($sel_res)) {
> echo "Couldn't delete $ID\n";
> } else {
> echo "False positive result, there is no $ID in the table\n";
> }
> } else {
> echo "There aren't any $ID in the table\n";
> }
> } else {
> if($rows=mysql_affected_rows($del_res)) {
> echo "Number of entries deleted: $rows\n";
> } else {
> echo "There wasn't anything to delete\n";
> }
> }
>
> This should give you a better understanding why the delete failed.
>
>
> //Aho
I get back "There aren't any 59 in the table"
where 59 is the row i am trying to delete
Mark
| |
| J.O. Aho 2006-04-25, 7:03 pm |
| Mark D. Smith wrote:
> "J.O. Aho" <user@example.net> wrote in message
> news:4b1ve0Fvh1iiU1@individual.net...
> Delete
>
> I get back "There aren't any 59 in the table"
> where 59 is the row i am trying to delete
The user you login as to the sql server, does that user have the privilige to
delete from the table?
//Aho
| |
| richard.a.fletcher@googlemail.com 2006-04-25, 7:03 pm |
| So it worked the first time because it's not there now?
|
|
|
|