Jump to content

mysql problem


golanu21

Recommended Posts

addEventHandler("onPlayerJoin", getRootElement(), 
function () 
zombie_db = connectToDB() 
x, y, z = getElementPosition(source) 
dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) 
end) 

why when i enter in game with same name a new row is appear ...with same name and same valors...

Link to comment

(Did you ever create the table?)

Try this: ((Not Tested))

local zombie_db = connectToDB() 
addEventHandler("onPlayerJoin", getRootElement(), function () 
    local x, y, z = getElementPosition(source) 
    dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) 
end) 

Link to comment
(Did you ever create the table?)

Try this: ((Not Tested))

local zombie_db = connectToDB() 
addEventHandler("onPlayerJoin", getRootElement(), function () 
    local x, y, z = getElementPosition(source) 
    dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) 
end) 

P.S: same error :D

Link to comment
-- Exemplu de conectare la MySQL 
  
local host = "secret"; 
local dbname = "secret"; 
local username = "secret"; 
local password = "secret"; 
  
function connectToDB() 
    zombie_db = dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") 
    return zombie_db 
  
end 
  
function creeazaTabel() 
    zombie_db = connectToDB() 
     local characters = dbExec( zombie_db, "CREATE TABLE IF NOT EXISTS characters (id INT NOT NULL AUTO_INCREMENT, nume VARCHAR(50) NOT NULL, model INT NOT NULL, health FLOAT NOT NULL, posx FLOAT NOT NULL, posy FLOAT NOT NULL, posz FLOAT NOT NULL, PRIMARY KEY (id))") 
     end 
addEventHandler("onResourceStart", getRootElement(getThisResource()), creeazaTabel) 
  
  
local zombie_db = connectToDB() 
ip = 0 
addEventHandler("onPlayerJoin", getRootElement(), function () 
    if ip == 0 then 
    local x, y, z = getElementPosition(source) 
    dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) 
    ip = 1 
    elseif ip == 1 then 
    cancelEvent() 
    end 
end) 
  
addEventHandler("onPlayerQuit", getRootElement(), 
function () 
zombie_db = connectToDB() 
             
dbExec( zombie_db, "UPDATE characters SET nume=?,  health=?", getPlayerName(source), getElementHealth(source)) 
end 
) 
  
function viataCandSpawneaza() 
zombie_db = connectToDB() 
                        local second = dbQuery( zombie_db, "SELECT * FROM characters WHERE nume=?", getPlayerName(source)) 
                        local result, numrows = dbPoll(second, -1) 
                            if (result and numrows > 0) then 
                                  for index, row in pairs(result) do  
                                        setElementHealth(source, row['health']) 
                                   end 
                            end 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), viataCandSpawneaza ) 
  

this is the full code, but i fixed it with a variabile 0, and when player join, set variabile 1, and when variabile is 1 cancelevent :D

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