Jump to content

why is update limiting me to 255 characters or less?


Go to solution Solved by vinny42,

Recommended Posts

I am trying to update the post_content on a mysql blog and of course that normally will allow a huge amount of characters... but for some reason I am not being allowed to do the update via php unless the text length of the update is under 255 characters.. if I exceed the 255 it says failed.. under 255 works fine..

 

Any suggestions.

$id = 877;

$mydat = must be 255 or less...

include("connect-vicky-info.php");

$sql="UPDATE wp_posts SET post_content='$mydat' WHERE ID='$id'";

$result=mysql_query($sql);

if($result){
echo "<br><b>Successful!</b><br><br>";
} else {
echo "<br><font color=red><b>Negative Result.<b></font><br><br>";
}


Sounds like you are trying to insert into a VARCHAR column, they have a default limit of 255 characters.

 

backup your database, and use an ALTER TABLE statement to change the offending column from VARCHAR to TEXT.

 

Doing this is very low-risk, but do *NOT* skip the backup, and check if you can actually restore the backup on a test environment before yoou risk destroying your data.

Well I will look at it just for shits and giggles, but as I stated above.. it is the post_content field in a word press blog.. and since its the content section and sometimes needs to hold several pages of data I doubt it would be restricted to 255 characters since all of mine have a 3 or 4 thousand on very page... and I am trying to edit and replace the same date... take it out edit it and put it back... but it won't go back..

This does not make any sense...

Also just for experiment i will go to the SQL panel and see if I can do manual SQL and put in more... now I know for sure I can export it into csv then edit and import back.. but I really need to do it one by one... not a ton of csv... messing the entire table...

Any other thoughts..

 

Just thought of another possibility.. will read the post_content then edit and try to instantly update (replace) but I am pretty sure that won't work either... damn this is annoying..

Edited by tommytx

Sounds like you are trying to insert into a VARCHAR column, they have a default limit of 255 characters.

 

 

varchar(255) has a limit of 255 chars, varchar(1000) has a limit of 1000 chars.

 

How is post_content defined in your table, and what is your maximum size that you want to store?

Its a longtext field.. I thought everyone knew that wp blog post_content would be a huge text field since sometimes it holds several pages of infomation..

 

When directly accessing a longtext field is there anything I need to tell the program so it knows how to handle a long text field... there is no reason it should consider it a 255 max for long text..

Maybe I will post this on the wordpress site.. maybe they will have some idea... makes not sense to me..

Edited by tommytx

Not sure what that is supposed to do.. I went to mysql and wp_posts and executed that which gave the below.. no info.. basically

 

wp_posts CREATE TABLE `wp_posts` (
 `ID` bigint(20) unsign...

 

But it a simple matter to look at the structure for posts_comments and see that it is a "longtext" capable of handling a whole lot more than 255 characters... if anyone has the time I would greatly appreciate it if you could run my tiny php file and see if you can update a large paragraph...

and I did try the below and it woud not write it either.. even though the data is already being held by the same post_content..

Its really wild as you can see it grabs a full page with images from post id 1 of the post_content column but will not post same to the id 877.. gets a fail and the data is not stored... makes no sense..  I would be forever in someone's debt if you could take the time to simulate and tell me what I am doing wrong... its very important and holding up an important project.  Thanks in advance.

<?php
include("connect-vicky-info.php");
$id = 1;
$sql = "SELECT post_content FROM `wp_posts` WHERE ID='$id'";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
$post_content =  $row['post_content'] . "<br>";
echo "$post_content<br>";
$id = 877;
$sql="UPDATE wp_posts SET post_content='$post_content' WHERE ID='$id'";
$result=mysql_query($sql);
if($result){
echo "<br><b>Successful!</b><br><br>";
} else {
echo "<br><font color=red><b>Negative Result.<b></font><br><br>";
}
?>

  • Solution

 


varchar(255) has a limit of 255 chars, varchar(1000) has a limit of 1000 chars.

 

Yup, and just about every database management tool will suggest 255 as the default limit.

 

 


But it a simple matter to look at the structure for posts_comments and see that it is a "longtext" capable of handling a whole lot more than 255 characters...

 

So it's probaby not that field that's causing the problem. 

What is the exact errormessage?

well yes it was that field, especially since it is the only field I am using... but your question about what is the exact error.. got me back to the basics and I removed that dinky little nothing error report above that tells you absolutely nothing but that it failed.. so I added the mysql error reporter as I should have to begin with and it called out an error with something like... we've meaning it did not like the ' symbol.. so before submitting the update I now have the program scan every character and escape this little sucker... like so.. \' and all is well.. Thanks for getting my brain spinning with the "exactly what is the error" that brought me back to basics and a solution.. Thank you very much... I can move on now to the next molehill that I will be able to make into a MOUNTAIN.. HaHa..

 

For anyone who is following this thread to learn... here is the error monitor i added and got rid of the useless one above.

 

$result=mysql_query($sql) or die("MySQL error has occurred.-> Your Query: " . $sql . "<br/> Error: (" . mysql_errno() . ") " . mysql_error())
 

Edited by tommytx

 


 it did not like the ' symbol.. so before submitting the update I now have the program scan every character and escape this little sucker... like so.. \' and all is well.. 

 

Uhm.. you *are* using mysql's own escape functions, right? if not then you have to do that *NOW* because you're completely open to SQL injection.

Don't escape the3 quote manually, because the quote is only one of many characters that need to be escaped and you have no way of doing that right withcustom code.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.