Jump to content

Empty SQL Tables


Thorxx

Recommended Posts

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

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
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

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 ) 

mta-screen_2014-02-19_16-45-22.png

Link to comment
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 ) 

mta-screen_2014-02-19_16-45-22.png

The 'acc' Parameter doesn't return for the player account so you must make it like this :

getAccountName( getPlayerAccount ( source ) ) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...