Page 1 of 2
Varchar is too big I guess.
Posted: Sat Apr 14, 2007 9:11 pm
by Mightywayne
Howdy. I'm logging battles for my game, right, and these logs can get -big-.
The problem here is I try to add the log to the database... the log itself is fine, I've printed it with echo and it runs well. But I tried to put the battle log into "mediumblob" mode, and I guess it's the formatting tags (<b> for bold and stuff). So I figured, okay, we'll just use varchar. Oh no no. It doesn't want me to do that. I keep changing varchar to be like varchar(999999) and it changes back to "mediumtext". I need like 500,000 chars at most, but still it won't let me.
What should I do?
Posted: Sat Apr 14, 2007 9:39 pm
by thunderbox
varchar only goes up to 255.... for 500,000 you will need mediumtext or mediumblob.. and then just limit it to 500000... (e.g. MEDIUMTEXT(500000) )
Posted: Sat Apr 14, 2007 11:20 pm
by Mightywayne
Yes... but, the problem is, mediumtext won't allow me to put symbols like > or < in there.
Posted: Sun Apr 15, 2007 1:14 am
by Charles256
are you positive? because if you're echoing it out to a browser and it's showing you
bold text it could be it echoed out <b>bold text</b> and your browser simply interpeted it for ya?

Posted: Sun Apr 15, 2007 7:29 am
by Mightywayne
I'm pretty positive, yes. o.o; It won't add it to the database. Just, won't. I add it like regular updating and it won't go in.
Edit: More clearly, it says "NULL" under the entry.
Posted: Sun Apr 15, 2007 9:46 am
by feyd
That is a likely result of your insertion code. The field type can store anything.
Posted: Sun Apr 15, 2007 11:19 am
by Mightywayne
Hmm... well, okay. I'll explicitly look through it all soon.
Should it matter that I use <br>'s and stuff? I change the font a lot, too... hmm.
Posted: Sun Apr 15, 2007 11:47 am
by superdezign
feyd wrote:The field type can store anything.
HTML code can go in and out of the database fine. Sounds to me like your missing your single-quotes, but I'm sure by now you would have noticed if that was the case.
Posted: Sun Apr 15, 2007 12:59 pm
by Mightywayne
=/ Got the problem.
I set the battlelog to be like..
$battlelog .= "(what happens)" then at the end of the battle, it just throws out the battlelog. That works well, and keeps the "s and 's in there. However, upon sending it to the database, it trips over the first ' it sees.
Could not connect: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 's message:
"I challenge thee to a duel of massive proportions."
And, that's the first thing that shows up. The battle starts off like...
Challenger's message:
"I challenge thee to a duel of massive proportions."
But even then, it doesn't even get to the fighters' battle to screw up, though when I "fix" the message to work, it will, and then still screw up when I change the font to red because I had to use font='red'
What should I do? Am I really going to have to store each log in a seperate text file and just print that out?
Posted: Sun Apr 15, 2007 1:07 pm
by John Cartwright
you should always pass your data through mysql_real_escape_string() when inserting into the database
Posted: Sun Apr 15, 2007 1:09 pm
by Mightywayne
Oh wow. I think I actually get it.. so it will strip the correct stuff away.
And is this used for security purposes, also? There's no insertable fields... you just click to do the battle and it goes.
Edit: Hmm... tried it and it didn't fix it. =/ I'll try escaping more things I guess.
Posted: Sun Apr 15, 2007 1:12 pm
by John Cartwright
Yes it is for security purposes, to avoid sql injection and simply escape quotes, among other things.
There's no insertable fields... you just click to do the battle and it goes.
I thought you were inserting logs into the database?
Posted: Sun Apr 15, 2007 1:28 pm
by Mightywayne
I am, but if they have to field to insert SQL commands into, how will they put the SQL in?
Edit: I don't know what I did. I think I did something with quotes and escaping. But I just got it to work. ^^
Posted: Sun Apr 15, 2007 1:36 pm
by John Cartwright
Mightywayne wrote:I am, but if they have to field to insert SQL commands into, how will they put the SQL in?
I have no idea what you just said, please rephrease.
Mightywayne wrote:Edit: I don't know what I did. I think I did something with quotes and escaping. But I just got it to work. ^^
It would be helpful to see your code, to make sure you are doing things correctly.
Posted: Sun Apr 15, 2007 1:46 pm
by Mightywayne
Sorry, I'm being distracted by terrible things I don't want to mention.
I am, but if they have no field to insert SQL commands into, how will they put the SQL in?
And the code's really big and I frankly don't feel comfortable posting my whole battle script in the open, and since people don't seem to like to help on a personal level (I don't blame you), I'll just work out the current problems I have, I guess.
Edit: It broke again because I can't use INSERT. I have to use UPDATE to add it, and I can't do that, because I guess it just doesn't like that.
Edit 2: Okay, I got it I think. I can't use double quotes for my message, which kinda sucks, I'm sure I'll figure out a way for it work eventually. The problem was inserting '$log', instead I did \"$log\" and it loved me again.