Fix SQL INSERT problems with PHP addslashes function

If you’ve created you own custom content management system using PHP, you may have noticed problems inserting data. One of the problems could be that your data may have characters that prevent it from being inserted. Some of the character that would cause this type of problem are single or double quotes, backslash, and NUL characters.

You can escape these problematic characters using the PHP function addslashes(). As explained by the PHP manual: It returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote (), double quote (), backslash (\) and NUL (the NULL byte).

As you can see from my example below, I first run the content through the addshashes function and than return it to the same named string “$Page_Content” before passing it to my SQL UPDATE or INSERT statement.

$Page_Content = addslashes($Page_Content);
$query = "UPDATE site_content SET Page_Title='$Page_Title', Page_Content='$Page_Content' WHERE id_f='$id_f'";
query_db($query);

Create MySQL Database With PHP

Create a dynamic web site by using MySQL Database and PHP. It is easy and I provided the code to cut and paste. Continue Reading »

PHPRunner

PHPRunner builds visually appealing web interface for any local or remote MySQL database. Your web site visitors will be able to easily search, add, edit, delete and export data in MySQL database. Advanced security options allow to build password-protecte
Continue Reading »

PHP Order By Multiple Fields in MySQL

Want to be able to order by two or more database fields / columns using the ASC and DESC order clause
Continue Reading »