MySQL Error 1136
#1

I am back in using mySQL once again, the last time i used it is way way back in 2012 with the Secret Formula Thing Server Project which fails.

So anyway let's get to the point, I have been following [HiC]TheKiller's MySQL tutorial, i have corrected some errors from his tutorial though, However i am getting this strange warning.

Код:
CMySQLHandler::Query(INSERT INTO `users` (`username`, `password`, `ip`, `registerdate`, `helmet`, `admin`, `vip`, `scores`, `money`, `kills`, `deaths`, `rank`) VALUES('[S]JaKe', SHA1('cactus'), '192.168.1.100', '03/25/2015', 0, 0, 0, 30000, 0, 0, 0)) - An error has occured. (Error ID: 1136, Column count doesn't match value count at row 1)
Note, the password cactus isn't the original password of mine i changed it due to the privacy.

Code:

PHP код:
stock RegisterPlayer(playeridpasswordstring[])
{
    new 
query[600];
    
    new 
yearExmonthExdayEx;
    
getdate(yearExmonthExdayEx);
    
format(pInfo[playerid][RegisterDate], 90"%02d/%02d/%d"monthExdayExyearEx);
    
    
format(querysizeof(query), "INSERT INTO `users` (`username`, `password`, `ip`, `registerdate`, `helmet`, `admin`, `vip`, `scores`, `money`, `kills`, `deaths`, `rank`) VALUES('%s', SHA1('%s'), '%s', '%s', 0, 0, 0, 30000, 0, 0, 0)"nameEx(playerid), passwordstringpInfo[playerid][IP], pInfo[playerid][RegisterDate]);
    
mysql_query(query);
    print(
query);
    
GivePlayerMoney(playeridpInfo[playerid][Money]);
    
SendClientMessage(playerid, -1"Info: "col_y"You have been registered on this server!");
    
LoggedIn[playerid] = 1;
    return 
1;

How do i also insert userid (automatically) ?

I AM USING MYSQL R5
Reply
#2

Error #1136 means that the number of specified columns in the INSERT() query doesn't match the values.

In this case, you had 12 fields specified, but you only filled in 11.

Try:

pawn Код:
INSERT INTO `users` (`username`, `password`, `ip`, `registerdate`, `helmet`, `admin`, `vip`, `scores`, `money`, `kills`, `deaths`, `rank`) VALUES('%s', SHA1('%s'), '%s', '%s', 0, 0, 0, 30000, 0, 0, 0, 0)
Reply
#3

Thanks bro! I forgot what is the nickname i have given to you, it was long time ago, but never mind!

* cookies given *
Reply
#4

how do u also do the userid system auto insert system thingy? i am in my mobile phone atm
Reply
#5

The field has to have AUTO_INCREMENT enabled (SERIAL alias field type is bigint(20) unsigned AUTO_INCREMENT). When inserting you can either list fields you want to update, or just pass null as id value, so it updates automatically.
Reply
#6

Also, you could set a default value in your database for half of your columns (the ones where you pass 0).
I suppose you want to give each player $30000 when they create an account, so the others (helmet, admin, vip, scores, kills, deaths, rank) can be left out of the query.
MySQL will then fill in the default values by itself when you don't pass them along.

Your query will be alot shorter and easier to fix when you have an error.

Old query:
pawn Код:
INSERT INTO `users` (`username`, `password`, `ip`, `registerdate`, `helmet`, `admin`, `vip`, `scores`, `money`, `kills`, `deaths`, `rank`) VALUES('[S]JaKe', SHA1('cactus'), '192.168.1.100', '03/25/2015', 0, 0, 0, 30000, 0, 0, 0)
New query:
pawn Код:
INSERT INTO `users` (`username`, `password`, `ip`, `registerdate`, `money`) VALUES('[S]JaKe', SHA1('cactus'), '192.168.1.100', '03/25/2015', 30000)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)