carlosx2 Posted October 29, 2009 Share Posted October 29, 2009 I have a problem it seems with sending over long pieces of text to mysql. i have a form with a story that is being send to a registration file in php. All is fine even when i i put the var by print_r i see the long piece of text wich is about 564 thats not that many. I have a table in mysql setup with a text row to hold this story but for some reason its only stores my text when i submit around 189 I don't get what i am doing wrong. Its is just not accepting more. did i forget a certain setting or something? Quote Link to comment Share on other sites More sharing options...
cags Posted October 29, 2009 Share Posted October 29, 2009 What version of MySQL are you using? What datatype is the column your attempting to submit? Quote Link to comment Share on other sites More sharing options...
SchweppesAle Posted October 29, 2009 Share Posted October 29, 2009 Try changing the attribute(column) into another datatype http://php.about.com/od/mysqlcommands/g/mysql_change.htm Text Columns http://dev.mysql.com/doc/refman/5.0/en/string-type-overview.html Quote Link to comment Share on other sites More sharing options...
carlosx2 Posted October 29, 2009 Author Share Posted October 29, 2009 i am using phpMyAdmin - 2.11.9.5 * MySQL client version: 5.1.30 data type i am using is text, in mysql that is. Quote Link to comment Share on other sites More sharing options...
carlosx2 Posted October 29, 2009 Author Share Posted October 29, 2009 this is the code i am using to post to the sql database <title>Done</title><?PHP $user_name = ""; $password = ""; $database = ""; $server = ""; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); $testname = $_POST[title]; $query = "SELECT * FROM dvd WHERE title='$_POST[title]'"; $result = mysql_query($query); $num = mysql_num_rows($result); if ($num == 0) { $SQL = "INSERT INTO dvd (title, date, time, models , niche , models2 , models3 , models4 , models5 , models6 , models7 , models8 , story ) VALUES ('$title' , '$date' , '$time' , '$models' , '$niche' , '$models2' , '$models3' , '$models4' , '$models5' , '$models6' , '$models7' , '$models8' , '$story')"; $result = mysql_query($SQL); mysql_close($db_handle); print "DVD has been added to the database. <p> <a href='dvdcreator.php'>Add another DVD</a>"; print_r ($SQL); } else { print "DVD has already been entert into the database. hit the back button</a>"; mysql_close($db_handle); } ?> it still not working. checked with my wp blog that also uses the same mysql and there its working. so i think it might be the code or something. Then again when i so not that many char its all working perfect. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 change it to a text column in teh db, that should do the trick, it should be ok for a small database Quote Link to comment Share on other sites More sharing options...
cags Posted October 29, 2009 Share Posted October 29, 2009 data type i am using is text, in mysql that is. change it to a text column in teh db, that should do the trick, it should be ok for a small database Do you even read threads before you post? Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 data type i am using is text, in mysql that is. change it to a text column in teh db, that should do the trick, it should be ok for a small database Do you even read threads before you post? not all of it no, original poster , you may have a slashing problem wich is killing it, you need to add slashes oi recon (maybe), isue is with single quotes, hyphens Quote Link to comment Share on other sites More sharing options...
carlosx2 Posted October 29, 2009 Author Share Posted October 29, 2009 could it be possible that my php ini is keeping me from posting so many char, would be possible. i already looked at my php ini but i can't find anything that would keep me from sending that many char to my db. also i am not sure where to look Quote Link to comment Share on other sites More sharing options...
carlosx2 Posted October 29, 2009 Author Share Posted October 29, 2009 data type i am using is text, in mysql that is. change it to a text column in teh db, that should do the trick, it should be ok for a small database Do you even read threads before you post? not all of it no, original poster , you may have a slashing problem wich is killing it, you need to add slashes oi recon (maybe), isue is with single quotes, hyphens i am not sure what you mean by you may have a slashing problem Quote Link to comment Share on other sites More sharing options...
cags Posted October 29, 2009 Share Posted October 29, 2009 If you have certain characters in the text you are inserting (such as single quote) and the data isn't being escaped that would explain the issue. Your code doesn't really show where $story (I assume that's the field in question) is coming from. That sort of leads me to believe you might be using register_globals, which is bad, but thats another story. Before the insert statement try adding... $story = mysql_real_escape_string($story); Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 If you have certain characters in the text you are inserting (such as single quote) and the data isn't being escaped that would explain the issue. Your code doesn't really show where $story (I assume that's the field in question) is coming from. That sort of leads me to believe you might be using register_globals, which is bad, but thats another story. Before the insert statement try adding... $story = mysql_real_escape_string($story); or addslashes(), i think single quotes conflict with the query itself, other than that mysql will add slashes to everything else and remove them when brogth out, you need to addslashes($string) and then remove them when you bring it out removeslashes or preg_replace() "insert into table values('blah "blah" bla's');" it can add and remove slashes from "blah" but blah' will end the value Quote Link to comment Share on other sites More sharing options...
cags Posted October 29, 2009 Share Posted October 29, 2009 Whilst technically that would work, it's highly recommended to use the specific escape function for your technology. Quote Link to comment Share on other sites More sharing options...
carlosx2 Posted October 29, 2009 Author Share Posted October 29, 2009 well this is all coming from a form to submit all this data. i fill in the form hit submit and you are done. its is about $story yes. so i use the post action that bring it to this site to process it the database. where do i enter that one line. ? before i run the sent to code? Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 if its object oriented you need to find where its inserting the code eg something like tablename->insert(); basicaly to whatever your form posts to. action=filepostedto.php or maybe php self if its directly in teh query $sql = "insert into table values(".$story.")" just go to the page it posts to and do a search for insert or new or create or add Quote Link to comment Share on other sites More sharing options...
cags Posted October 29, 2009 Share Posted October 29, 2009 Like I said, before the Insert statement. Yes I figured it's all coming from a posted form, but at no point in the code you have shown so far do you show a value being assigned to $story. Which means either a). you just didn't post it, or b). your server has register_globals enabled, which is not really recommended. Quote Link to comment Share on other sites More sharing options...
carlosx2 Posted October 29, 2009 Author Share Posted October 29, 2009 ok it worked by just adding $story = mysql_real_escape_string($story); but i have to find out how and why it worked this way. so next time i know how to use it and why. so i need to teach myself this little piece of code. thanks for the help. this place is really great. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 ok it worked by just adding $story = mysql_real_escape_string($story); but i have to find out how and why it worked this way. so next time i know how to use it and why. so i need to teach myself this little piece of code. thanks for the help. this place is really great. short texts almost never have single quotes, long texts usualy paragraphs with hyphens cancel out the query beaus the query itself has a single quote to delimit values, a single quote in your string will read like values('blah's') it will end at 'blah' mysql handles slashing for everything else, you will need to remove the slashes for this one on teh way out otherwise every time you edit it it will get an extra slash and you have loads of slahses Quote Link to comment Share on other sites More sharing options...
cags Posted October 29, 2009 Share Posted October 29, 2009 Your code is like this... $SQL = "INSERT INTO dvd (title, date, time, models , niche , models2 , models3 , models4 , models5 , models6 , models7 , models8 , story ) VALUES ('$title' , '$date' , '$time' , '$models' , '$niche' , '$models2' , '$models3' , '$models4' , '$models5' , '$models6' , '$models7' , '$models8' , '$story')"; Now imagine that $story holds something like... $story = "I'm great"; If you subsitute that into your query, the end of your query now reads... '$models8' , 'I'm great')" As you can see the single quote will escape the string thus only I will be inserted. You really need to run all your strings through mysql_real_escape_string() for security purposes anyway, otherwise somebody could use SQL Injection on your site. Faux Edit: You do not have to call stripslashes to get rid of the slashes, because they aren't really in your database. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 Faux Edit: You do not have to call stripslashes to get rid of the slashes, because they aren't really in your database. thats what you would think, but from experience i know they will go in, because mysql isnt adding these slashes so it wont remove them, they become part of your string, the first slash wont show, but when you edit it, the second slash will, it will keep on slashing it every time you edit, first slash will be removed but in teh db, to wich another slash will be added on edit, you need to add slashes on edit too. swhen you insert into the text box in your interface strip the slashes, the first slash is invisible, only when there are two it will become visible Quote Link to comment Share on other sites More sharing options...
carlosx2 Posted October 29, 2009 Author Share Posted October 29, 2009 ok i get it. the only weird thing is that in the text i tried to enter there weren't any of these ' or anything else. just .... thats all. but i understand i should do it for each string Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 ok i get it. the only weird thing is that in the text i tried to enter there weren't any of these ' or anything else. just .... thats all. but i understand i should do it for each string annoying isnt it, if you were mvc'd you could oiveride the insert method of teh base class of model Quote Link to comment Share on other sites More sharing options...
cags Posted October 29, 2009 Share Posted October 29, 2009 Faux Edit: You do not have to call stripslashes to get rid of the slashes, because they aren't really in your database. thats what you would think, but from experience i know they will go in, because mysql isnt adding these slashes so it wont remove them, they become part of your string, the first slash wont show, but when you edit it, the second slash will, it will keep on slashing it every time you edit, first slash will be removed but in teh db, to wich another slash will be added on edit, you need to add slashes on edit too. swhen you insert into the text box in your interface strip the slashes, the first slash is invisible, only when there are two it will become visible Yes, that is what I would think, because it is correct. The only time the slashes should appear in the inserted data is if you have badly written code/server setting combination. If you use mysql_real_escape_string, the only time you should get the slashes in your data, and hence have to remove them is if the data is being double escaped. This could be caused by magic quotes being enabled on the server, but since the OP was getting a problem with unescaped data, this doesn't appear to be the case for them. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 Faux Edit: You do not have to call stripslashes to get rid of the slashes, because they aren't really in your database. thats what you would think, but from experience i know they will go in, because mysql isnt adding these slashes so it wont remove them, they become part of your string, the first slash wont show, but when you edit it, the second slash will, it will keep on slashing it every time you edit, first slash will be removed but in teh db, to wich another slash will be added on edit, you need to add slashes on edit too. swhen you insert into the text box in your interface strip the slashes, the first slash is invisible, only when there are two it will become visible Yes, that is what I would think, because it is correct. The only time the slashes should appear in the inserted data is if you have badly written code/server setting combination. If you use mysql_real_escape_string, the only time you should get the slashes in your data, and hence have to remove them is if the data is being double escaped. This could be caused by magic quotes being enabled on the server, but since the OP was getting a problem with unescaped data, this doesn't appear to be the case for them. ok il keep that in mind thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.