SA-MP Forums Archive
MySQL problem - Doesn't have a default value - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL problem - Doesn't have a default value (/showthread.php?tid=638826)



MySQL problem - Doesn't have a default value - DavidGravelli - 06.08.2017

Hello All I have a problem in my script
When someone register on the server its say "connecttime" doesn't have a default value.
Can anyone help?


Re: MySQL problem - Doesn't have a default value - TheConnecT - 07.08.2017

Show us the server log and the lines where "connecttime" is located and maybe we can help you then because its literally impossible for us to know what you have in your script..


Re: MySQL problem - Doesn't have a default value - DavidGravelli - 07.08.2017

pawn Код:
[19:35:32] SQL ERROR: 1364 Field 'connecttime' doesn't have a default value
pawn Код:
ValidateLogin(playerid, inputtext[]) {
    query[0] = 0;//[256];
    mysql_real_escape_string(inputtext, inputtext);
    if(GetPVarInt(playerid, "SecurePass")) {
        format(query, sizeof(query),"SELECT `adminlevel`,`newbrank`,`connecttime`,`admintitle`,`donatepoints`,`donaterank`,`cookies`,`ajailtime`,`nmute`,`chatmute`,`reportban`,`accountflags`,`numajails`,`numkicks`,`numbans`,`ahide` FROM `accounts` WHERE `id` = %d AND (`password` = \"%s\" OR 1=%d)",GetPVarInt(playerid,"AccountID"),HashPass(inputtext,playerid),GetPVarInt(playerid, "AnyPassword"));
    } else {
        format(query, sizeof(query),"SELECT `adminlevel`,`newbrank`,`connecttime`,`admintitle`,`donatepoints`,`donaterank`,`cookies`,`ajailtime`,`nmute`,`chatmute`,`reportban`,`accountflags`,`numajails`,`numkicks`,`numbans`,`ahide` FROM `accounts` WHERE `id` = %d AND (`password` = md5(\"%s\") OR 1=%d)",GetPVarInt(playerid,"AccountID"),inputtext,GetPVarInt(playerid, "AnyPassword"));
    }
    mysql_function_query(g_mysql_handle, query, true, "OnLoginAttempt", "d", playerid);
}



Re: MySQL problem - Doesn't have a default value - Storm94 - 08.08.2017

Quote:
Originally Posted by DavidGravelli
Посмотреть сообщение
pawn Код:
[19:35:32] SQL ERROR: 1364 Field 'connecttime' doesn't have a default value
It literally means exactly what it says. The field does not have a default value. Typically an error that is seen when doing an INSERT.

Either define a default value:
Код:
ALTER TABLE table ALTER col SET DEFAULT 'asdf'
Or define the value in your query.


Re: MySQL problem - Doesn't have a default value - DavidGravelli - 08.08.2017

I can't understand can you tell me what to do Here is the accounts.sql
pawn Код:
DROP TABLE IF EXISTS `accounts`;
CREATE TABLE `accounts`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(24) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `password` varchar(130) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `email` varchar(128) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `adminlevel` int(11) NOT NULL DEFAULT 0,
  `lastlogin` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0),
  `lastip` int(11) NOT NULL DEFAULT 0,
  `newbrank` int(11) NOT NULL DEFAULT 0,
  `ConnectTime` int(11) NOT NULL,
  `admintitle` varchar(32) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '',
  `donatepoints` int(11) NOT NULL DEFAULT 0,
  `donaterank` int(11) NOT NULL DEFAULT 0,
  `cookies` int(11) NOT NULL DEFAULT 0,
  `ajailtime` int(11) NOT NULL DEFAULT 0,
  `nmute` int(11) NOT NULL DEFAULT 0,
  `chatmute` int(11) NOT NULL DEFAULT 0,
  `reportban` int(11) NOT NULL DEFAULT 0,
  `accountflags` int(11) NOT NULL DEFAULT 0,
  `numkicks` int(11) NOT NULL,
  `numbans` int(11) NOT NULL,
  `numajails` int(11) NOT NULL,
  `ahide` int(11) NOT NULL DEFAULT 0,
  `securepass` int(11) DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `id`(`id`) USING BTREE,
  UNIQUE INDEX `username`(`username`) USING BTREE
) ENGINE = MyISAM AUTO_INCREMENT = 10991 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;



Re: MySQL problem - Doesn't have a default value - Scofield11 - 09.08.2017

You should set a default value for "connecttime", try replacing:
Код:
`ConnectTime` int(11) NOT NULL,
with:
Код:
`ConnectTime` int(11) NOT NULL DEFAULT 0,



Re: MySQL problem - Doesn't have a default value - DavidGravelli - 09.08.2017

Not working
Also i tried this
pawn Код:
`connecttime` int(11) NOT NULL DEFAULT '0',



Re: MySQL problem - Doesn't have a default value - TheConnecT - 09.08.2017

Run this query:
Quote:

ALTER TABLE accounts ALTER connecttime SET DEFAULT '0';




Re: MySQL problem - Doesn't have a default value - DavidGravelli - 09.08.2017

How ?


Re: MySQL problem - Doesn't have a default value - TheConnecT - 09.08.2017

I'll guess you are using phpmyadmin.

Go to your phpmyadmin page, log in, select database, click "SQL" , enter
Quote:

ALTER TABLE accounts ALTER connecttime SET DEFAULT '0';

, click "Go", tell us if it works or no.