itoko Posted June 4, 2011 Posted June 4, 2011 Hi, i have a problem with a panel script, by mysql database. The script is connected to the database, but there are no table in the database, so nothng can be saved, or loaded. The default table is 'userdata', but in the database, there are no table created and im not a very good scripter, so i ask your help. is there the mysql part of the script: -- Database connection info sqlHostname = "***.**.**.***" sqlUsername = "*********" sqlPassword = "*******" sqlDefaultDatabase = "*********" sqlDefaultTable = "userdata" -- Connect to the database function mySQLConnect() sqlConnection = mysql_connect(sqlHostname,sqlUsername,sqlPassword,sqlDefaultDatabase) end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),mySQLConnect) -- Make a new entry to the mySQL database function checkSqlData(source) if (sqlConnection == nil) then mySQLConnect() end local player = source local serial = getPlayerSerial(player) local entryCheck = sqlConnection:query("SELECT serial FROM "..sqlDefaultTable.." WHERE serial='"..serial.."'") if (entryCheck) then local result = mysql_result(entryCheck,1,1) if (result == "") or (result == nil) then outputDebugString("New entry added to the mySQL database!") sqlConnection:query("INSERT INTO "..sqlDefaultTable.." (serial) VALUES ('"..serial.."')") sqlConnection:query("UPDATE "..sqlDefaultTable.." SET playerName='"..string.gsub(getPlayerName(player),"#%x%x%x%x%x%x", "").."' WHERE serial='"..serial.."'") end else outputDebugString("New entry added to the mySQL database!") sqlConnection:query("INSERT INTO "..sqlDefaultTable.." (serial) VALUES ('"..serial.."')") sqlConnection:query("UPDATE "..sqlDefaultTable.." SET playerName='"..string.gsub(getPlayerName(player),"#%x%x%x%x%x%x", "").."' WHERE serial='"..serial.."'") end end addEventHandler("onPlayerJoin",getRootElement(),checkSqlData) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function() for i,player in ipairs (getElementsByType("player")) do checkSqlData(player) end end) -- Load data from the database function loadPlayerData (player,datatype) if (sqlConnection == nil) then restartResource(getThisResource()) end if (player) and (datatype) then local serial = getPlayerSerial(player) local findQuery = sqlConnection:query("SELECT "..datatype.." FROM "..sqlDefaultTable.." WHERE serial='"..serial.."'") if (findQuery) then local result = mysql_result(findQuery,1,1) if not (result == nil) then if not (result == "") then mysql_free_result(findQuery) return result else mysql_free_result(findQuery) return 0 end else return 0 end else --outputDebugString("Failed to get "..datatype.." for player "..getPlayerName(player).." @ findQuery") --outputDebugString("mysql_query failed: (" .. mysql_errno(sqlConnection) .. ") " .. mysql_error(sqlConnection)) end end end -- Save data to the database function savePlayerData (player,datatype,newvalue) if (sqlConnection == nil) then restartResource(getThisResource()) end if (player) and (datatype) and (newvalue) then local serial = getPlayerSerial(player) local saveData = sqlConnection:query("UPDATE "..sqlDefaultTable.." SET "..datatype.."='"..newvalue.."' WHERE serial='"..serial.."'") if (saveData == nil) then outputDebugString("Error executing the save query: (" .. mysql_errno(sqlConnection) .. ") " .. mysql_error(sqlConnection)) end end end i hope someone can help me. Regards, Itoko bruh
BriGhtx3 Posted June 4, 2011 Posted June 4, 2011 ? What is the error? In the table userdata, isn't another table? Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
itoko Posted June 4, 2011 Author Posted June 4, 2011 they are no table, that the problem. and sorry i forgotten the error they are bad arguments #1 on all tonumber: value expected (to change the money, stats ect) and when i try change my personal details: error executing the save query: (line) table 'username.userdata' doesn't exist (i mean the sqlUsername) bruh
BriGhtx3 Posted June 4, 2011 Posted June 4, 2011 Then just create the table? Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
itoko Posted June 4, 2011 Author Posted June 4, 2011 but when i create new table its ask me type, lenght and decimal bruh
BriGhtx3 Posted June 4, 2011 Posted June 4, 2011 I would say it is time to learn. it says to you LENGTH AND DECIMAL. What don't you understand? Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
itoko Posted June 4, 2011 Author Posted June 4, 2011 is that i ask, what i put in? how i need to create it for my panel bruh
BriGhtx3 Posted June 4, 2011 Posted June 4, 2011 (edited) CREATE TABLE Userdata ( Username VARCHAR (100) ); Query this. Edited June 4, 2011 by Guest Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
itoko Posted June 4, 2011 Author Posted June 4, 2011 [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 4 hmm sry i dont use mysql normally so bruh
BriGhtx3 Posted June 4, 2011 Posted June 4, 2011 You have to query this in your database and not in the script Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
itoko Posted June 4, 2011 Author Posted June 4, 2011 yes i did it with navicat and it said me error, i did it with phpmyadmin too bruh
BriGhtx3 Posted June 4, 2011 Posted June 4, 2011 Try it now again : CREATE TABLE Userdata ( Username VARCHAR (100) ); Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
itoko Posted June 5, 2011 Author Posted June 5, 2011 ok thx the table is created, but i have the same problem with all tonumber, its dont work, and the error table doesn't exist is now: error executing the save query: (1054) unkown column 'serial' in 'where cause' sry but i really dont know the sql bruh
BriGhtx3 Posted June 5, 2011 Posted June 5, 2011 -.- Then create this column? You should really read some tutorials about SQL. Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
itoko Posted June 5, 2011 Author Posted June 5, 2011 i hve other question, in the value of the colunm, if i put 100 it's for 100 accounts max? bruh
Orange Posted June 5, 2011 Posted June 5, 2011 You should really read some tutorials about SQL. http://zduniak.net - don't contact me regarding mta:sa
BriGhtx3 Posted June 5, 2011 Posted June 5, 2011 Yes but you wouldn't have to ask if you would read tutorials. Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
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