Jump to content
  • 0
TICHOJEBEC

pomoc MySQL R41-4 SAVE FILE

Dotaz

Nazdar chalani...potreboval by som poradiť. 

Mam vytvorenú registráciu z ukladaním PlayerInfo ako je id, meno, heslo, peniaze, smrti, AdminLVL a pod. Problém je ten, že keď v databáze upravím napríklad peniaze, pripojím sa na server tak údaje z databázy prečíta a mám peňazí toľko koľko som si nastavil v tabuľke ale keď si na servery prihodím peniaze alebo zmením AdminLVL, odpojím sa a znovu pripojím, neuloží zmeny do tabuliek. Viete mi s tým pomôcť? Ďakujem :)

PWN

Spoiler

enum pDataEnum
{
	p_id,  //Save
	bool:pLoggedIn,
	menohraca[MAX_PLAYER_NAME],  //Save
	adminlvl, //Save
	peniaze, //Save
	zabiti, //Save
	smrti, //Save
	mutedsec, //Save
	wanteds, //Save
	warns, //Save
	vw,
	specdata[2],
	Float:specpos[4],
	specid,
	bool:spec,
	Float:pos[3],
	int,
	#if defined SPECTATE_TEXTDRAW
		PlayerText:specTD
	#endif
}
new PlayerInfo[MAX_PLAYERS][pDataEnum];
public OnPlayerDisconnect(playerid, reason)
{
	SaveUserStats(playerid);
	return 1;
}
stock SaveUserStats(playerid)
{
	new query[256];
	if(PlayerInfo[playerid][pLoggedIn])
	mysql_format(handle, query, sizeof(query), "UPDATE users SET adminlvl = '%d', peniaze = '%d', zabiti = '%d', smrti = '%d' WHERE id = '%d'  WHERE mutedsec = '%d'  WHERE wanteds = '%d'  WHERE warns = '%d'", PlayerInfo[playerid][adminlvl], PlayerInfo[playerid][peniaze], PlayerInfo[playerid][zabiti], PlayerInfo[playerid][smrti], PlayerInfo[playerid][p_id], PlayerInfo[playerid][mutedsec], PlayerInfo[playerid][wanteds], PlayerInfo[playerid][warns]);
	mysql_pquery(handle, query);
	return 1;
}

SQL Tabuľka

Spoiler


-- phpMyAdmin SQL Dump
-- version 4.3.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Erstellungszeit: 13. Aug 2015 um 02:14
-- Server-Version: 5.6.24
-- PHP-Version: 5.6.8

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Datenbank: `samp_db`
--

-- --------------------------------------------------------

--
-- Tabellenstruktur fĂĽr Tabelle `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(10) NOT NULL,
  `name` varchar(64) DEFAULT NULL,
  `password` varchar(128) DEFAULT NULL,
  `adminlvl` int(3) NOT NULL DEFAULT '0',
  `peniaze` int(10) NOT NULL DEFAULT '0',
  `zabiti` int(10) NOT NULL DEFAULT '0',
  `smrti` int(10) NOT NULL DEFAULT '0',
  `wanteds` int(10) NOT NULL DEFAULT '0',
  `mutedsec` int(10) NOT NULL DEFAULT '0',
  `warns` int(10) NOT NULL DEFAULT '0'

) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Tabelle fĂĽr die Spieler-Statistiken';

--
-- Indizes der exportierten Tabellen
--

--
-- Indizes fĂĽr die Tabelle `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT fĂĽr exportierte Tabellen
--

--
-- AUTO_INCREMENT fĂĽr Tabelle `users`
--
ALTER TABLE `users`
  MODIFY `id` int(10) NOT NULL AUTO_INCREMENT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

 

Ešte som zabudol load... 

 


public OnPlayerConnect(playerid)
{
	PlayerInfo[playerid][p_id]       = 0;
	PlayerInfo[playerid][pLoggedIn]  = false;
	PlayerInfo[playerid][adminlvl]     = 0;
	PlayerInfo[playerid][peniaze]     = 0;
	PlayerInfo[playerid][zabiti]     = 0;
	PlayerInfo[playerid][smrti]    = 0;
	PlayerInfo[playerid][mutedsec]     = 0;
	PlayerInfo[playerid][wanteds]     = 0;
	PlayerInfo[playerid][warns]    = 0;
	GetPlayerName(playerid, PlayerInfo[playerid][menohraca], MAX_PLAYER_NAME);
	return 1;
}
public OnUserLogin(playerid)
{
	new rows;
	cache_get_row_count(rows);
	if(rows == 0)
	{
		//The player has typed in a wrong password
		ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "PRIHLASENIE", "PRIHLAS SA POMOCOV HESLA:\nZLÉ HESLO", "ZNOVA", "ZRUSIT");
	}
	else
	{
		//The player has typed in his correct password
 		cache_get_value_name_int(0, "id", PlayerInfo[playerid][p_id]);
		cache_get_value_name_int(0, "adminlvl", PlayerInfo[playerid][adminlvl]);
		cache_get_value_name_int(0, "peniaze", PlayerInfo[playerid][peniaze]);
		cache_get_value_name_int(0, "zabiti", PlayerInfo[playerid][zabiti]);
		cache_get_value_name_int(0, "smrti", PlayerInfo[playerid][smrti]);
		cache_get_value_name_int(0, "mutedsec", PlayerInfo[playerid][mutedsec]);
		cache_get_value_name_int(0, "wanteds", PlayerInfo[playerid][wanteds]);
		cache_get_value_name_int(0, "warns", PlayerInfo[playerid][warns]);
		
		PlayerInfo[playerid][pLoggedIn]  = true;
		SendClientMessage(playerid, COLOR_GREEN, "[SERVER] ÚSPEŠNE SI SA PRIHLÁSIL!");
		PlayerPlaySound(playerid, 1057 , 0.0, 0.0, 0.0);
		GivePlayerMoney(playerid, PlayerInfo[playerid][peniaze]);
		HideLoginTextDraws(playerid);
	}
	return 1;
}

 

 

Edited by TICHOJEBEC

Sdílet tento příspěvek


Link to post
Share on other sites

9 odpovědí na tuto otázku

Recommended Posts

  • 0

Niesom síce nejaký expert v MySQL, ale vieš čo znamená slovo WHERE ?

UPDATE users SET adminlvl = '%d', peniaze = '%d', zabiti = '%d', smrti = '%d' WHERE id = '%d'  WHERE mutedsec = '%d'  WHERE wanteds = '%d'  WHERE warns = '%d'

A načo vlastne ukladáš hráčové ID?
Keď sa po každom pripojení znova mení, alebo to máš vlastné ID podľa čoho vlastne ukladáš ?
 

UPDATE users SET adminlvl = '%d', peniaze = '%d', zabiti = '%d', smrti = '%d, id = '%d', mutedsec = '%d', wanteds = '%d', warns = '%d' WHERE playerName = '%s'

Updatni users, nastav admin level, peniaze, zabiti ...., ale iba tam kde hráčovo meno = "%s"

Sdílet tento příspěvek


Link to post
Share on other sites
  • 0
Spoiler

stock SaveUserStats(playerid)
{
	new query[256];
	if(PlayerInfo[playerid][pLoggedIn])
	mysql_format(handle, query, sizeof(query), "UPDATE users SET adminlvl = '%d', peniaze = '%d', zabiti = '%d', smrti = '%d, id = '%d', mutedsec = '%d', wanteds = '%d', warns = '%d' WHERE name = '%e'", PlayerInfo[playerid][adminlvl], PlayerInfo[playerid][peniaze], PlayerInfo[playerid][zabiti], PlayerInfo[playerid][smrti], PlayerInfo[playerid][p_id], PlayerInfo[playerid][mutedsec], PlayerInfo[playerid][wanteds], PlayerInfo[playerid][warns], PlayerInfo[playerid][menohraca]);
	mysql_pquery(handle, query);
	return 1;
}

stock SaveUserStats(playerid)
{
	new query[256];
	if(PlayerInfo[playerid][pLoggedIn])
	mysql_format(handle, query, sizeof(query), "UPDATE users SET adminlvl = '%d', peniaze = '%d', zabiti = '%d', smrti = '%d, id = '%d', mutedsec = '%d', wanteds = '%d', warns = '%d' WHERE name = '%s'", PlayerInfo[playerid][adminlvl], PlayerInfo[playerid][peniaze], PlayerInfo[playerid][zabiti], PlayerInfo[playerid][smrti], PlayerInfo[playerid][p_id], PlayerInfo[playerid][mutedsec], PlayerInfo[playerid][wanteds], PlayerInfo[playerid][warns], PlayerInfo[playerid][menohraca]);
	mysql_pquery(handle, query);
	return 1;
}

stock SaveUserStats(playerid)
{
	new query[256];
	if(PlayerInfo[playerid][pLoggedIn])
	mysql_format(handle, query, sizeof(query), "UPDATE users SET adminlvl = '%d', peniaze = '%d', zabiti = '%d', smrti = '%d, id = '%d', mutedsec = '%d', wanteds = '%d', warns = '%d' WHERE playerName = '%e'", PlayerInfo[playerid][adminlvl], PlayerInfo[playerid][peniaze], PlayerInfo[playerid][zabiti], PlayerInfo[playerid][smrti], PlayerInfo[playerid][p_id], PlayerInfo[playerid][mutedsec], PlayerInfo[playerid][wanteds], PlayerInfo[playerid][warns], PlayerInfo[playerid][menohraca]);
	mysql_pquery(handle, query);
  
  stock SaveUserStats(playerid)
{
	new query[256];
	if(PlayerInfo[playerid][pLoggedIn])
	mysql_format(handle, query, sizeof(query), "UPDATE users SET adminlvl = '%d', peniaze = '%d', zabiti = '%d', smrti = '%d, id = '%d', mutedsec = '%d', wanteds = '%d', warns = '%d' WHERE playerName = '%s'", PlayerInfo[playerid][adminlvl], PlayerInfo[playerid][peniaze], PlayerInfo[playerid][zabiti], PlayerInfo[playerid][smrti], PlayerInfo[playerid][p_id], PlayerInfo[playerid][mutedsec], PlayerInfo[playerid][wanteds], PlayerInfo[playerid][warns], PlayerInfo[playerid][menohraca]);
	mysql_pquery(handle, query);
	return 1;
}

 

Takto som to skusil 4 spôsobmi a stale to neuklada.... :(

Edited by TICHOJEBEC

Sdílet tento příspěvek


Link to post
Share on other sites
  • 0

Taak za prvé neviem prečo ukladáš hráčové meno do premennéj, a vôbec načo to je ?
A za druhé,pozri si ešte raz ako máš vytvorenú tabuľku a kde vlastne ukladáš to meno hráča, ten názov a následne pozri si WHERE .... kde hľadáš to hráčovo meno...
 

Sdílet tento příspěvek


Link to post
Share on other sites
  • 0
před 11 minutami, XpresS said:

Taak za prvé neviem prečo ukladáš hráčové meno do premennéj, a vôbec načo to je ?
A za druhé,pozri si ešte raz ako máš vytvorenú tabuľku a kde vlastne ukladáš to meno hráča, ten názov a následne pozri si WHERE .... kde hľadáš to hráčovo meno...
 

Meno hráča do tabuľky neukladam. Vidis niekde že by som ukladal meno hráča ? To že mám v premenných //Save neznamená že ho ukladám. 

Sdílet tento příspěvek


Link to post
Share on other sites
  • 0

A ďalšia vec

CREATE TABLE `players` (
  `ID` int(12) NOT NULL,
  `Username` varchar(24) NOT NULL,
  `Password` varchar(129) NOT NULL,
  `IPAddress` varchar(17) NOT NULL,
  `adminlvl` int(12) NOT NULL,
  `Cash` int(12) NOT NULL,
  `Kills` int(12) NOT NULL,
  `Deaths` int(12) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

máš vytvorenú tabuľku s menom players a ukladáš to do users...

A áno, predstav si tu máš napísané Username
Tak budem predpokladať, že to čo si dodal je aktuálne.

Sdílet tento příspěvek


Link to post
Share on other sites
  • 0
před 11 minutami, XpresS said:

A ďalšia vec


CREATE TABLE `players` (
  `ID` int(12) NOT NULL,
  `Username` varchar(24) NOT NULL,
  `Password` varchar(129) NOT NULL,
  `IPAddress` varchar(17) NOT NULL,
  `adminlvl` int(12) NOT NULL,
  `Cash` int(12) NOT NULL,
  `Kills` int(12) NOT NULL,
  `Deaths` int(12) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

máš vytvorenú tabuľku s menom players a ukladáš to do users...

A áno, predstav si tu máš napísané Username
Tak budem predpokladať, že to čo si dodal je aktuálne.

Sekol som sa s tabulkov...

 

Spoiler

-- phpMyAdmin SQL Dump
-- version 4.3.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Erstellungszeit: 13. Aug 2015 um 02:14
-- Server-Version: 5.6.24
-- PHP-Version: 5.6.8

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Datenbank: `samp_db`
--

-- --------------------------------------------------------

--
-- Tabellenstruktur fĂĽr Tabelle `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(10) NOT NULL,
  `name` varchar(64) DEFAULT NULL,
  `password` varchar(128) DEFAULT NULL,
  `adminlvl` int(3) NOT NULL DEFAULT '0',
  `peniaze` int(10) NOT NULL DEFAULT '0',
  `zabiti` int(10) NOT NULL DEFAULT '0',
  `smrti` int(10) NOT NULL DEFAULT '0',
  `wanteds` int(10) NOT NULL DEFAULT '0',
  `mutedsec` int(10) NOT NULL DEFAULT '0',
  `warns` int(10) NOT NULL DEFAULT '0'

) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Tabelle fĂĽr die Spieler-Statistiken';

--
-- Indizes der exportierten Tabellen
--

--
-- Indizes fĂĽr die Tabelle `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT fĂĽr exportierte Tabellen
--

--
-- AUTO_INCREMENT fĂĽr Tabelle `users`
--
ALTER TABLE `users`
  MODIFY `id` int(10) NOT NULL AUTO_INCREMENT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

 

 

Sdílet tento příspěvek


Link to post
Share on other sites
  • 0

Takže našiel som problém. Možno niekomu pomôže :)

 

Spoiler

Ukladanie ktoré som mal ja:

	mysql_format(handle, query, sizeof(query), "UPDATE users SET adminlvl = '%d', peniaze = '%d', zabiti = '%d', smrti = '%d' WHERE id = '%d'  WHERE mutedsec = '%d'  WHERE wanteds = '%d'  WHERE warns = '%d'", PlayerInfo[playerid][adminlvl], PlayerInfo[playerid][peniaze], PlayerInfo[playerid][zabiti], PlayerInfo[playerid][smrti], PlayerInfo[playerid][p_id], PlayerInfo[playerid][mutedsec], PlayerInfo[playerid][wanteds], PlayerInfo[playerid][warns]);

WHERE -> Ako som to pochopil ja...WHERE = KDE a samozrejme môže byť WHERE iba jedno a podľa toho zistí komu ma pripisať udaje...
Teraz to je správne :) Otestované všetko zapisuje 

	mysql_format(handle, query, sizeof(query), "UPDATE users SET adminlvl = '%d', peniaze = '%d', zabiti = '%d', smrti = '%d', mutedsec = '%d', wanteds = '%d', warns = '%d' WHERE id = '%d'", PlayerInfo[playerid][adminlvl], PlayerInfo[playerid][peniaze], PlayerInfo[playerid][zabiti], PlayerInfo[playerid][smrti], PlayerInfo[playerid][mutedsec], PlayerInfo[playerid][wanteds], PlayerInfo[playerid][warns], PlayerInfo[playerid][p_id]);

 

 

Sdílet tento příspěvek


Link to post
Share on other sites
  • 0

Jinak zareaguju jen na starsi thread: WHERE klauzule lze kombinovat pomoci logickych spojek tzn. AND / OR / NOT. Ovsem tim tvym zpusobem to nelze, protoze muze mit jen jeden dotaz jednu WHERE klauzuli, pokud se nejedna o nested

 

tzn ve tvem pripade: 

WHERE id='%d' AND mutedsec = '%d' AND wanteds = '%d' AND warns = '%d'

Sdílet tento příspěvek


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Odpovědět na dotaz...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Obnovili jsme váš původní obsah (obsah napsaný před zavřením).   Smazat obnovený obsah

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...