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);
Tagged : / / /

How to backup MySQL Database via SSH

First you log in using your terminal application by typing the flowing SSH command:

ssh yourusername@hostname-or-ipaddress

After that, you will be prompted to enter your password. As you enter your password, the text will be hidden. Next we should switch to the “root” user. You can do so by typing the following in your terminal window:

su – root

You will have to enter a password once more. Now navagate to where you would like to store your MySQL database file. For an example of changing the directory to the “public_html” direcotry, type this:

cd /var/www/html_public

Now you can back up your db here using the following command. This command will backup all of your databases. I also chose to compress them after the pipe “|” as a gzip file. Type the following but be sure to change the user name and password to your info:

mysqldump -u yourusername -p yourpassword –all-databases | gzip >databasebackup.sql.gz

You can also target single database using the following:

mysqldump -u yourUserName -p yourDBName | gzip >databasebackup.sql.gz

Tagged : / / / /

Installing PHP MySQL Apache on windows 98 in 5 min

This article on “Installing Apache-MySQL-PHP on Windows 98” in just five min is a complete step by step tutorial to install this trio package. The article contains full graphics snapshots to help the new developers to install the trio package without any Continue reading “Installing PHP MySQL Apache on windows 98 in 5 min”

Tagged : / / /