Forum Moderators: coopster

Message Too Old, No Replies

Multiple textarea insert to mysql

         

cool capybara

9:37 pm on Feb 8, 2004 (gmt 0)



I have seven textarea fields being inserted to a mysql database. The php is very simple and I don't think I have an error there (read a textarea into a string, insert the string).

When I have a lot of complex characters (quotes, single quotes, colons, html tags etc.), I get a mysql error. I can remove pieces of text, but there doesn't seem to an exact culprit...that is, I can put a simple sentence in with all the aforementioned characters and there is no problem. But with long pieces of text, it craps out. Removing text piece by piece seems to suggest there is a length issue (I can keep removing until I just have a line of simple text and it still craps out until I remove a certain # of characters).

Also, it seems that one text field only makes the routine crap out depending on what is in another text field. I suspect that something about the datatype is making the input blend together or something.

I can go into mysql and manually put everything in and there is no problem.

I've checked and there is no need for something like addslashes()... Really, length seems to be of issue. is the fact that most fields will be under 255 characters be an issue?

Any suggestions on what the problem might be?

---

My routine:
* has seven <textarea> elements, each written to a string
* use nl2br() on each string and insert to mysql (each is of type TEXT)
* includes " ' : and html tags (<b> and <a href=>)
* Most <textarea> are under 255 characters but can be over

-- A simple sentence with all aforementioned characters is fine.
-- The text making it crap out can be manually inserted to mysql
-- I can delete portions of text until it works, but character type (e.g., quote, <tag>, etc.) doesn't seem to matter. The length seems to matter more.

Thanks for any suggestions!

transactiongeek

12:01 pm on Feb 9, 2004 (gmt 0)



Weird problem.

Can you put in an echo of a bad data example and post the echo to webmasterworld?

eg:

$val=nl2br($_REQUEST['textarea']);
echo "[$val]";
mysql_query("insert into example values ('$val')");

And then post to WebmasterWorld the echo'd values.

Also, maybe you want to try using htmlspecialchars? Not sure if it'll help, but it'll give you some more data points on trying to debug this.