SQL Errors
#1

Well, my SQL database aint saving data properly, and i'm not sure why, i'm sooo close, i just need to fix this little bit.


Some screens of the database





The outcome from the server log:


My admin level should be 3, my kills 1, my money 1000, my clan member 1, and my donator level 5, it's all seemed to of moved one up (so my admin level is 5 instead of 3)
Reply
#2

Awww..cmon, someones gotta know surely, I REALLY need to get this done
Reply
#3

Do you really expect to get help without showing your code?
Reply
#4

Try downloading the MySQL GUI tools and copypasta'ing suspected queries into the Query Browser and see if they work or what errors the return.
Reply
#5

one question: why do you use varchar for integers/digits?
Reply
#6

ahh, he must've forgotten free_result and other stuff like that I beleave
that gave me an error that the query was empty, too
Reply
#7

I also get this at the bottom of my PHPmyadmin screen:

Code:
The mbstring PHP extension was not found and you seem to be using a multibyte charset. Without the mbstring extension phpMyAdmin is unable to split strings correctly and it may result in unexpected results.
I'm very new to SQl i'm afraid, but i wanted to try somthing new, as my gamemode is awefully unstable using Dini and i have alot of accounts, so it fills up my space, so SQL is my way forward.

EDIT:

Also when I made myself admin here's what the log's came up with:

Code:
[09:58:37] Error in mysql_query: Query was empty
Reply
#8

Quote:
Originally Posted by Thanatos
one question: why do you use varchar for integers/digits?
Code:
Money = "a lot"
He's right though, they should be "int"'s if you plan on storing numbers.

Code:
[09:58:37] Error in mysql_query: Query was empty
I'm guessing that your query didn't work, so you are probably not an admin.
Reply
#9

No, nothing saves, apart from the account, and the password, everything else is basically telling me to fuck off, cause it don't wanna work.

Code:
-- phpMyAdmin SQL Dump
-- version 2.11.9.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 29, 2009 at 11:10 AM
-- Server version: 5.0.45
-- PHP Version: 5.1.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `dbhex127`
--

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

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
 `Username` varchar(30) NOT NULL,
 `Password` varchar(50) NOT NULL,
 `Money` int(10) NOT NULL default '0',
 `Kills` int(10) NOT NULL default '0',
 `Deaths` int(10) NOT NULL default '0',
 `Admin` int(10) NOT NULL default '0',
 `Donator` int(10) NOT NULL default '0',
 `Cmem` int(10) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`Username`, `Password`, `Money`, `Kills`, `Deaths`, `Admin`, `Donator`, `Cmem`) VALUES
('[UF]XtreaMeR', 'eb02afeb8d9580122adfccf7e62c48eb', 0, 0, 0, 0, 0, 0);
There, my database.
Reply
#10

Here's more code that could be useful:

Code:
MySQLNewColumns() //initializes new rows to the current table!
{
	new haystack[64];
	format(haystack,sizeof(haystack),"SHOW columns FROM `users`");
	samp_mysql_query(haystack);
 	samp_mysql_store_result();
	if(samp_mysql_num_rows() < 10)
	{
		samp_mysql_query("ALTER TABLE `users` ADD Admin INT(10) NOT NULL DEFAULT '0'");
		samp_mysql_query("ALTER TABLE `users` ADD Donator INT(10) NOT NULL DEFULT '0'");
		samp_mysql_query("ALTER TABLE `users` ADD cmem INT(10) NOT NULL DEFULT '0'");
		samp_mysql_query("CREATE TABLE IF NOT EXISTS `banlist`(`id` INT(11) NOT NULL auto_increment PRIMARY KEY,\
		`Name` VARCHAR(30) NOT NULL,\
		`IP` VARCHAR(40) NOT NULL,\
		`Reason` TINYTEXT NOT NULL)");
	}
	return 1;
}
You mean this?

The registering and shit work, and my password saves properly, but money, kills, deaths, admin level, donator level, and clan membership will not save.


Code:
stock RegPlayer(playerid,pass[])
{
  MySQLCheck();
  new pName[MAX_PLAYER_NAME],
		query[256],
		string[256];
		
	GetPlayerName(playerid,pName,sizeof(pName));
	samp_mysql_real_escape_string(pName,pName);
	samp_mysql_real_escape_string(pass,pass);
	format(query,sizeof(query),"INSERT INTO `users` (Username,Password) VALUES ('%s',md5('%s'))",pName,pass);
	samp_mysql_query(query);
	samp_mysql_free_result();

	format(string,sizeof(string),">> Account %s successfully registered ( Password: %s )",pName,pass);
	SendClientMessage(playerid,GREY,string);
	SendClientMessage(playerid,GREY,"You have been automatically logged in");
	LoggedIn[playerid] = 1;
	AccRegistered[playerid] = 1;
	AccountInfo[playerid][Money] = 0;
	AccountInfo[playerid][Kills] = 0;
	AccountInfo[playerid][Deaths] = 0;
	AccountInfo[playerid][AdminLevel] = 0;
	AccountInfo[playerid][DonatorLevel] = 0;
	AccountInfo[playerid][ClanMember] = 0;
	return 1;
}

stock LoginPlayer(playerid,pass[])
{
  new pName[MAX_PLAYER_NAME],
		query[256],
		string[256],
		result[256],
		loop[256],
		poop = 1;

	GetPlayerName(playerid,pName,sizeof(pName));
	MySQLCheck();
	samp_mysql_real_escape_string(pName,pName);
	samp_mysql_real_escape_string(pass,pass);
	format(query,sizeof(query),"SELECT * FROM `users` WHERE Username = '%s' AND Password = md5('%s')",pName,pass);
	samp_mysql_query(query);
	samp_mysql_store_result();
	samp_mysql_fetch_row(result);
	
	if(samp_mysql_num_rows() == 1)
	{
	  samp_mysql_strtok(loop, "|", result);
	  while(samp_mysql_strtok(loop, "|", ""))
		{
		  if(poop == 3) AccountInfo[playerid][Money] = strval(loop);
		  if(poop == 4) AccountInfo[playerid][Kills] = strval(loop);
		  if(poop == 5) AccountInfo[playerid][Deaths] = strval(loop);
		  if(poop == 6) AccountInfo[playerid][AdminLevel] = strval(loop);
  		  if(poop == 7) AccountInfo[playerid][DonatorLevel] = strval(loop);
  		  if(poop == 8) AccountInfo[playerid][ClanMember] = strval(loop);
		  poop++;
		}
		samp_mysql_free_result();

		GivePlayerMoney(playerid,AccountInfo[playerid][Money]);
		LoggedIn[playerid] = 1;
		format(string,sizeof(string),">> You have been successfully logged in. (Kills/Score: %d | Deaths: %d | Money: %d | Donator Level %d)",AccountInfo[playerid][Kills],AccountInfo[playerid][Deaths],AccountInfo[playerid][Money],AccountInfo[playerid][DonatorLevel]);
		SendClientMessage(playerid,GREY,string);
		if(AccountInfo[playerid][AdminLevel] > 0)
		{
		  new send[128];
		  format(send,sizeof(send),">> %s has logged in as level %d Admin",pName,AccountInfo[playerid][AdminLevel]);
		  SendClientMessageToAll(YELLOW,send);
		}
		printf("User %s has logged in ( Money: %d,Kills/Score: %d,Deaths: %d, Donator level: %d )",pName,AccountInfo[playerid][Money],AccountInfo[playerid][Kills],AccountInfo[playerid][Deaths],AccountInfo[playerid][DonatorLevel]);
		return 1;
	}
	else
	{
	  SendClientMessage(playerid,RED,">> Wrong Password");
	  Wrongattempt[playerid] += 1;
	  printf("Bad log in attempt by %s (Total attempts: %d)",pName,Wrongattempt[playerid]);
	}
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)