SQLite Problem
#1

I made a command.
pawn Код:
if(!strcmp(cmdtext, "/number", true))
    {
        new query[256], DBResult:Result;

        format(query, sizeof(query), "SELECT * FROM `Users` WHERE `Name` = '%s'", ReturnName(playerid));
        Result = db_query(iDatabase, query);

        if(!db_num_rows(Result))
        {
            new number[10];

            number[0] = '0';
            number[1] = '7';
            number[2] = (1 + random(8)) + '0';
            for(new i = 3; i < 10; i++)
            number[i] = random(10) + '0';

            format(query, sizeof(query), "INSERT INTO `Users` (`Name`,`Number`) VALUES('%s','%s')", ReturnName(playerid), DB_Escape(number));
            db_free_result(db_query(iDatabase, query));
            format(query, 128, "Name: %s | Phone number: %s", ReturnName(playerid), DB_Escape(number));
            SendClientMessage(playerid, -1, query);
        }
        return 1;
}
And look what happens:
Database: http://imageshack.us/photo/my-images/29/errorem.png/
Message : http://imageshack.us/f/121/samp033uy.png/
Reply
#2

Image is failing to load, therefore I don't know the problem :/
Reply
#3

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Image is failing to load, therefore I don't know the problem :/
http://imageshack.us/photo/my-images/121/samp033uy.png/
Reply
#4

Why do you need to use DB_Escape? For it? Why not just use Db_get_field_assoc instead or just have the query (string) formatted without the DB_escape on the phone number string?
Reply
#5

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Why do you need to use DB_Escape? For it? Why not just use Db_get_field_assoc instead or just have the query (string) formatted without the DB_escape on the phone number string?
Can you show me an example ? Thanks in advice.
PS: But lol, for what db_get_field_assoc ? I don't need it. I must insert the number, lol.
Reply
#6

pawn Код:
new Field[20], iNumber[20];
db_get_field_assoc(iDatabase, "Number", Field, 20);
format(iNumber, 20, "%s", Field);
Reply
#7

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
pawn Код:
new Field[20], iNumber[20];
db_get_field_assoc(iDatabase, "Number", Field, 20);
format(iNumber, 20, "%s", Field);
I'm trying to insert the number in database, not to extract him .
Reply
#8

The only thing I saw wrong in the image is the SendClientMessage thing, thats what i'm trying to help you fix :P
Reply
#9

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
The only thing I saw wrong in the image is the SendClientMessage thing, thats what i'm trying to help you fix :P
http://imageshack.us/photo/my-images/29/errorem.png/ ( I've changed from Users to Clients )
Reply
#10

Ohh then, replace ' DB_Escape(number) ' with just ' number ' without the '

After that show me your results.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)