MySQL Delete query
#1

Hello everyone, I have made a command to remove a row from my "notes" table.
Everything works well, and when I do the command, it sends me a message: u have removed note ID [note id].. and if I enter an invalid note ID it tells that it's invalid. The only problem is that it doesn't remove the note, here's my removing note script:

PHP код:
forward RemoveNoteFunc(playerid);
public 
RemoveNoteFunc(playerid)
{
    new
        
rows,
        
fields;
    
cache_get_data(rowsfieldsmysql);
    
    if(
rows)
    {
        new 
madebythenoteidquery[128];
        
madeby cache_get_row_int(05);
        
thenoteid cache_get_row_int(00);
        if(
pInfo[playerid][Admin] < && pInfo[playerid][ID] != madeby) return SendErrorMSG(playerid"You cannot remove a note unless it's made by you.");
        new 
string[128];
        
mysql_format(mysqlquerysizeof(query), "DELETE * FROM notes WHERE `ID` = %d"thenoteid);
        
mysql_tquery(mysqlquery"""");
        
format(stringsizeof(string), "You have removed note ID %d."thenoteid);
        
SendAdminMSG(playeridstring);
        
format(stringsizeof(string), "%s(%d) has removed note ID %d."PlayerName(playerid), playeridthenoteid);
        
SendALogMSG(string);
    }
    else
    {
         
SendErrorMSG(playerid"Invalid note ID.");
    }
    return 
1;

Reply
#2

https://sampwiki.blast.hk/wiki/MySQL/R33..._affected_rows

You can see how many rows were affected and if it is not 0, show the messages about removing note ID.
I'm not entirely sure if there is only one row, if the function returns 0. The note box in wiki states a DELETE query without WHERE clause.

I guess you execute a query to get the the note ID from another table, right? This can be done in one query.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/MySQL/R33..._affected_rows

You can see how many rows were affected and if it is not 0, show the messages about removing note ID.
I'm not entirely sure if there is only one row, if the function returns 0. The note box in wiki states a DELETE query without WHERE clause.

I guess you execute a query to get the the note ID from another table, right? This can be done in one query.
So if it's an invalid note ID, the "cache_affected_rows" will return 0?
Reply
#4

Quote:
Originally Posted by Ahmed21
Посмотреть сообщение
So if it's an invalid note ID, the "cache_affected_rows" will return 0?
Yes because no rows will be deleted (affected).
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Yes because no rows will be deleted (affected).
Okay great thank you so much! +REP'd :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)