Sunday, May 20, 2012

dodfr on “ERROR While Uploading an image to the post”

Hello, I am new at wordpress but do some PHP/MySQL and I found the answer to this error, in fact when this error appear you can't insert image into post as once you click "upload" button nothing happend, I saw a lot of posts about thos two porblems that seems to be linked, but strangely, when I do a quick post I can insert an image.

Solution to your problem is simple but I can't explain if it is a bug in WP or in MySQL Table declaration.

Go to "wp_posts" table uqing any MySQL database manager and change 'post_parent" that is bigint(20) unsigned to signed so when you try to insert picture that make WP produce a negative parent ID, value will be accepted.

I can't tell you if negative value produced by WP is a bug or not, but thinking of it it should not produce negative as field's name is "post_parent" so should be a parent's post ID that should be positive numbers.

I cannot tell you if my fix is "clean" but it worked for me.

Edit : I found a german thread about same problem and I think I was not wrong changing to "signed", but the post say the problem is because of "strict" mode used by MYSQL 5 and propose an other approach by adding this small code instead of changing database structure :

In function "__construct" inside "wp-includes/wp-db.php"

find this line :

if (!$this->dbh) {

and add this after it :

$mysql_version=trim(mysql_get_server_info());
if (substr($mysql_version,0,1)>'4')
{
//Disable "STRICT" mode for MySQL 5!
$this->query("SET SESSION sql_mode=''");
}

regards.