mysql DELETE syntax on 3.23.58
mysql DELETE syntax on 3.23.58
am 23.04.2006 18:42:29 von Mark D Smith
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
Re: mysql DELETE syntax on 3.23.58
am 23.04.2006 20:30:23 von Shion
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
Re: mysql DELETE syntax on 3.23.58
am 23.04.2006 22:12:08 von Mark D Smith
"J.O. Aho" wrote in message
news:4b1ve0Fvh1iiU1@individual.net...
> 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
I get back "There aren't any 59 in the table"
where 59 is the row i am trying to delete
Mark
Re: mysql DELETE syntax on 3.23.58
am 24.04.2006 05:54:13 von Shion
Mark D. Smith wrote:
> "J.O. Aho" wrote in message
> news:4b1ve0Fvh1iiU1@individual.net...
>> 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
>
> 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
Re: mysql DELETE syntax on 3.23.58
am 24.04.2006 10:29:54 von richard.a.fletcher
So it worked the first time because it's not there now?