This is how to make a PHP mysqli DELETE query with a prepared statement. This example includes error checking at every step. Error checking will help you debug your prepared mysqli query when it’s failing and you don’t know why. You can use this example to help you debug any mysqli prepared statement, not only … Read more →
Archive for “PHP Code Snippets”
PHP code snippets and tips for customizing your own website, and for generating dynamic content with PHP.
This lets you print PHP variable information, or any debugging code, to the screen, but only on your IP address. This is useful when you have to test on a live site, and for whatever reason you want to print to the screen rather than to error logs, but you don’t want visitors to see … Read more →
Get a human-readable debug backtrace including the the file, the function which calls it, and its line number. Usage: The following will print it directly to your WordPress error log (/wp-content/debug.log).
This gets the visitor’s IP address, and hides the content from the IP address that you specify. This is for use on WordPress sites. One way to use it is in your single.php template file (or content-single.php). Replace this: … with this: Be sure to change the ‘126.96.36.199’ on line 21 above to the IP … Read more →
Here is a way of preparing a large amount of data to insert into a MySQL database table via PHP. This method works if your data is split up into multiple text files. If your data is already in a single text file, see Harvesting Data From A Text File instead. Note: My example is … Read more →
Here is a way of preparing a large amount of data to insert into a MySQL database table via PHP. This method works if your data is all in one text file. If your data is split up into multiple text files, see Harvesting Data From Multiple Text Files To Insert Into MySQL instead. Note: … Read more →
Updated to use MySQL transactions, prepared SQL statments, and bound parameters. This lets you insert data from a PHP array into your MySQL database table. It will insert multiple rows into the table, where each row will take values from one array element. Before inserting, you must prepare your data into an array consisting of … Read more →
This is for you if you are using the WordPress Comment Notifier Plugin by Satollo. The purpose of this is to automatically subscribe your existing commentators (which are people who have already made comments to your blog). You want to add these people as subscribers to this Comment Notifier Plugin, or they get left out … Read more →
This is a PHP function to get the current page URL with only PHP. This works within WordPress, as well. Example Usage One use for this is if you’re using ajax to process a form and return results to the page, and you’d like a link below the results to allow the user to “Return … Read more →
This is a PHP function to convert time from 24-hour format (HH:MM) into 12-hour format, with am or pm added. It takes two parameters: the hour the minute (with a leading zero for 0 through 9) It returns the time in 12-format like this: HH:MM am/pm