Thorxx Posted February 19, 2014 Share Posted February 19, 2014 Hello, I've a little problem with SQL Tables. Here's my code: function logChat (msg) outputChatBox(getPlayerName(source).." has writen this: "..msg) dbExec( database, "INSERT INTO ChatLogs VALUES (ID, Time, Username, IP, Serial, Message)", 1, time, getPlayerName(source), getPlayerIP(source), getPlayerSerial(source), msg) end addEventHandler("onPlayerChat", getRootElement(), logChat) When player sends something it creates an empty line in my SQL server, why does it happen? Image: http://www.img.tpx.cz/uploads/A63da3ad.png Link to comment
myonlake Posted February 19, 2014 Share Posted February 19, 2014 That's because you're not defining the values (the values are defined as column names in your script). Also, your ID doesn't work, because you haven't set it to AUTO_INCREMENT, it will always have ID 1, which makes no sense really. function logChat( msg ) outputChatBox( getPlayerName( source ) .. " has written this: " .. msg, root ) dbExec( database, "INSERT INTO `ChatLogs` (`Time`, `Username`, `IP`, `Serial`, `Message`) VALUES ('?', '?', '?', '?', '?')", getRealTime( ).timestamp, getPlayerName( source ), getPlayerIP( source ), getPlayerSerial( source ), msg ) end addEventHandler( "onPlayerChat", root, logChat ) Make sure you set the ID column to AUTO_INCREMENT and make it a PRIMARY KEY. Link to comment
Thorxx Posted February 19, 2014 Author Share Posted February 19, 2014 Error: Line 32: dbExec( database, "INSERT INTO `ChatLogs` (`Time`, `Username`, `IP`, `Serial`, `Message`) VALUES ('?', '?', '?', '?', '?')", getRealTime( ).timestamp, getPlayerName( source ), getPlayerIP( source ), getPlayerSerial( source ), msg ) Link to comment
myonlake Posted February 19, 2014 Share Posted February 19, 2014 Weird, try this then. dbExec( database, "INSERT INTO `ChatLogs` (Time, Username, IP, Serial, Message) VALUES ('?', '?', '?', '?', '?')", getRealTime( ).timestamp, getPlayerName( source ), getPlayerIP( source ), getPlayerSerial( source ), msg ) Link to comment
Thorxx Posted February 19, 2014 Author Share Posted February 19, 2014 Still the same error. Link to comment
abu5lf Posted February 19, 2014 Share Posted February 19, 2014 Check if connection to database or not. Link to comment
Thorxx Posted February 19, 2014 Author Share Posted February 19, 2014 Check if connection to database or not. The code that you posted works. dbExec( database, 'INSERT INTO `ChatLogs`( Time, Username, IP, Serial, Message ) VALUES( ?, ?, ?, ?, ? )', getRealTime(), getPlayerName( source ), getPlayerIP( source ), getPlayerSerial( source ), msg ) Thanks Link to comment
Thorxx Posted February 19, 2014 Author Share Posted February 19, 2014 And one more thing left to solve function logChat( msg, acc ) dbExec( database, 'INSERT INTO `ChatLogs`( Date, Time, Username, Playername, IP, Serial, Message ) VALUES( ?, ?, ?, ?, ?, ?, ? )', getRealTime().monthday.."/"..getRealTime().month.."/"..getRealTime().year+1900, getRealTime().hour..":"..getRealTime().minute..":"..getRealTime( ).second, getAccountName( acc ), getPlayerName( source ), getPlayerIP( source ), getPlayerSerial( source ), msg ) end addEventHandler( "onPlayerChat", root, logChat ) Exactly: getAccountName( acc ) Link to comment
iPrestege Posted February 19, 2014 Share Posted February 19, 2014 And one more thing left to solve function logChat( msg, acc ) dbExec( database, 'INSERT INTO `ChatLogs`( Date, Time, Username, Playername, IP, Serial, Message ) VALUES( ?, ?, ?, ?, ?, ?, ? )', getRealTime().monthday.."/"..getRealTime().month.."/"..getRealTime().year+1900, getRealTime().hour..":"..getRealTime().minute..":"..getRealTime( ).second, getAccountName( acc ), getPlayerName( source ), getPlayerIP( source ), getPlayerSerial( source ), msg ) end addEventHandler( "onPlayerChat", root, logChat ) Exactly: getAccountName( acc ) The 'acc' Parameter doesn't return for the player account so you must make it like this : getAccountName( getPlayerAccount ( source ) ) Link to comment
myonlake Posted February 19, 2014 Share Posted February 19, 2014 You're welcome. You didn't even post any code. You're welcome, lol. Link to comment
Thorxx Posted February 19, 2014 Author Share Posted February 19, 2014 You're welcome. You didn't even post any code. You're welcome, lol. He did, but I copied it before he deleted the code. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now