Varchar is too big I guess.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Varchar is too big I guess.

Post 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?
thunderbox
Forum Newbie
Posts: 13
Joined: Wed Mar 07, 2007 4:06 pm

Post 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) )
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Yes... but, the problem is, mediumtext won't allow me to put symbols like > or < in there.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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? :-D
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That is a likely result of your insertion code. The field type can store anything.
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you should always pass your data through mysql_real_escape_string() when inserting into the database
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post 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.
Last edited by Mightywayne on Sun Apr 15, 2007 1:27 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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?
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post 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. ^^
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

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