Problem with phone system
#1

Hey guys,
so i have this problem that it generates the number fine. but it doesent save it .. heres the code:

pawn Код:
forward NumberExists(numb);
public NumberExists(numb)
{
    new value;
    new string[256];
    CheckMySQL();
    format(string, sizeof(string), "SELECT * FROM numbers WHERE number = '%d'",numb);
    mysql_query(string);
    mysql_store_result();
    if(mysql_num_rows())value = 0;
    else value = 1;
    return value;
}
forward MakePNumber(playerid,p);
public MakePNumber(playerid,p)
{
    new number2 = Random(56000000,78000000);
    if(NumberExists(number2) == 1)
    {
        MakePNumber(playerid,p);
        print("Number already exists");
    }
    else if(NumberExists(number2) == 2)
    {
        new s[255];
        UserStats[playerid][number] = number2;
        UserStats[playerid][phone] = p;
        CheckMySQL();
        format(s, sizeof(s), "INSERT INTO numbers (number) VALUES ('%d')",number2);
        mysql_query(s);
        SavePlayer(playerid);
        print("New number!");
    }
    return 1;
}
Thx for help
Reply
#2

You mean it doesn't save into table `numbers`?
Or you mean it doesn't save for the players?
Reply
#3

both
Reply
#4

The 2nd problem is because you are only saving a number
Try this
pawn Код:
new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof name);
    format(s, sizeof(s), "INSERT INTO numbers (username, number) VALUES ('%s', '%d')", name, number2);
    mysql_query(s);
For the first problem, do you connect to MySQL?
Reply
#5

Yep, i have the connection other things save

but, the table numbers is meant like, when it creates a number it checkes from the numbers table that does the generated number already exists if not its gonna save it as players phone number and its gonna insert the number to the table if the number already exists in the database it generates another number
Reply
#6

Do you get printed 'New number!'?
Reply
#7

No .. thats the prob
Reply
#8

Try this

pawn Код:
forward NumberExists(numb);
public NumberExists(numb)
{
    new value;
    new string[256];
    CheckMySQL();
    format(string, sizeof(string), "SELECT * FROM numbers WHERE number = '%d'",numb);
    mysql_query(string);
    mysql_store_result();
    if(mysql_num_rows() == 0)
    {
        value = 0;
    }
    else value = 1;
    return value;
}
forward MakePNumber(playerid,p);
public MakePNumber(playerid,p)
{
    new number2 = Random(56000000,78000000);
    if(NumberExists(number2) == 1)
    {
        MakePNumber(playerid,p);
        print("Number already exists");
    }
    else
    {
        new s[255];
        UserStats[playerid][number] = number2;
        UserStats[playerid][phone] = p;
        CheckMySQL();
        format(s, sizeof(s), "INSERT INTO numbers (number) VALUES ('%d')",number2);
        mysql_query(s);
        SavePlayer(playerid);
        print("New number!");
    }
    return 1;
}
Reply
#9

Thx,

lol my mistake

i got it
Reply
#10

No problem
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)