Better than nothing

Category: PHP/mySQL

Prevent FCKEditor from converting image tags to input tags

FCK Editor is a free, open-source HTML editor that is commonly used in a variety of CMS (content management systems). It is often installed as a Drupal plugin and we use it in our own CMS at work. Unfortunately, it has a pesky default that converts image tags to input tags. If you add a linked image like this:

<a href=”…”><img src=”…” /></a>

it saves it as a linked input like this:

<a href=”…”><input type=”image” src=”…” /></a>

This can create CSS issues in some browsers because image inputs are displayed with a blue border. To prevent your image tags from being converted to input tags, you have to dig into the FCKEditor code and tweak it slightly. Every time I have to do this, it takes me an hour to find the code that needs to be changed. Hopefully, this will save someone else a lot of time and hassle…

1) Open this file:

editor/dialog/fck_image/fck_image.js

2) Scroll down to about line 223. You will see this code:

if ( bImageButton )
{
	oImage = FCK.EditorDocument.createElement( 'INPUT' ) ;
	oImage.type = 'image' ;
	oImage = FCK.InsertElementAndGetIt( oImage ) ;
}
else
	oImage = FCK.CreateElement( 'IMG' ) ;

3) Change it to this:

if ( bImageButton )
{
	//oImage = FCK.EditorDocument.createElement( 'INPUT' ) ;
	//oImage.type = 'image' ;
	//oImage = FCK.InsertElementAndGetIt( oImage ) ;
	oImage = FCK.CreateElement( 'IMG' ) ;
}
else
	oImage = FCK.CreateElement( 'IMG' ) ;

problem solved! woo hoo!

How to fix Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in… blah blah blah.

If you need to useĀ  mysql_free_result(), you may have received this error. What causes it and how can you fix it?

First, what is mysql_free_result()? When you make mySQL database queries that return large sets of data, it can cause your server to bog down because those results are hogging up a lot of memory. On a high-traffic site, it can actually crash your server as more and more of those results build up. So, mysql_free_result() is a built-in PHP function that releases the results of your query from memory. Again, this is usually not a big deal unless you are returning large data sets from your queries, but it is always good practice to clear your results and free up the memory on your server. Here is an example of what the PHP code might look like:


//...CONNECT TO DATABASE...

$query = "SELECT * FROM employees WHERE age >= 30";
if ($result = mysql_query($query)) {
	while ($row = mysql_fetch_array($result)) {		
		//...DO SOMETHING HERE...
	}
	mysql_free_result($result); //free the query results from memory
}

///...CLOSE YOUR DATABSE CONNECTION...

But, if you have strict PHP warnings enabled on your server, you may start getting the warning above for some (but not all) of your queries. I had a really hard time tracking this problem down, but I finally found it here. You only use mysql_free_result() for the following query types: SELECT, SHOW, EXPLAIN, and DESCRIBE. So, if you perform an UPDATE query, it doesn’t return a valid resource and throws the warning when you call mysql_free_result(). Duh.

Page 2 of 2

Powered by WordPress & Theme by Anders Norén