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'";
First you log in using your terminal application by typing the flowing SSH command:
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:
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
How to filter / remove duplicate items in your database query result using DISTINCT
Continue reading “Select UNIQUE or DISTINCT MySQL/PHP Queries”
How to select and display records from MySQL table using the DISTINCT keyword for unique data.
Continue reading “MySQL DISTINCT to Remove Duplicate Listing”
Here’s how to order your data by two or more columns using PHP and MySQL Continue reading “PHP MySQL Order by Two Columns”
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 “Create MySQL Database With PHP”
Learn MySQL data types like Numeric Types, Date and Time Types and String Types for building dynamic web sites.
Continue reading “MySQL Table Fields Data Types”
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 “PHPRunner”
How to do a basic query from a MySQL database using PHP
Continue reading “Query Select From a Database”