<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>

    <title>Wavesdream</title>
    <link>/</link>
    <description>My Notes</description>

    
      <item>
        <title>HTML Form Validation Cheat Sheet</title>
        <link>/posts/html---form-validation/</link>
        <guid>/posts/html---form-validation/</guid>
        <pubDate>Fri, 10 Apr 2026 00:00:00 UTC</pubDate>
        <description>When I build a contact form or a complex application, I ensure that users enter the correct data that helps data accuracy and proper user experience.
In this article I am sharing a complete collection of commonly used HTML form validation patterns, attributes, and examples.
1. Basic Pattern Validations Only Alphabets
&amp;amp;lt;input type=&amp;amp;#34;text&amp;amp;#34; pattern=&amp;amp;#34;[A-Za-z\s]&#43;&amp;amp;#34; title=&amp;amp;#34;Only alphabets allowed&amp;amp;#34;&amp;amp;gt; Only Numbers
&amp;amp;lt;input type=&amp;amp;#34;text&amp;amp;#34; pattern=&amp;amp;#34;[0-9]&#43;&amp;amp;#34; title=&amp;amp;#34;Only numeric digits allowed&amp;amp;#34;&amp;amp;gt; Exactly 10 Digits (Mobile)
&amp;amp;lt;input type=&amp;amp;#34;text&amp;amp;#34; pattern=&amp;amp;#34;\d{10}&amp;amp;#34; maxlength=&amp;amp;#34;10&amp;amp;#34; oninput=&amp;amp;#34;this.value = this.value.replace(/[^0-9]/g, &amp;amp;#39;&amp;amp;#39;).slice(0,10);&amp;amp;#34; title=&amp;amp;#34;Enter exactly 10 digits&amp;amp;#34;&amp;amp;gt; Alphanumeric
</description>
      </item>
    
      <item>
        <title>Spam protection for WordPress Contact Form 7 plugin</title>
        <link>/posts/wordpress---contact-form-7-plugin-spam-protection/</link>
        <guid>/posts/wordpress---contact-form-7-plugin-spam-protection/</guid>
        <pubDate>Thu, 09 Apr 2026 00:00:00 UTC</pubDate>
        <description>In WordPress contact forms, mainly using Contact Form 7 plugin, everyone notices spam messages, SEO spam or bots flooding into email inbox.
There are options to use Google reCAPTCHA or Cloudflare Turnstile but custom PHP validation is another valid way to protect against spam.
There are several filters available in Contact Form 7 to validate form fields before submission of the form.
Put this piece of code in the functions.php file of the active theme.
</description>
      </item>
    
      <item>
        <title>Complete MySQL Commands Guide from Linux Terminal</title>
        <link>/posts/linux---useful-mysql-commands/</link>
        <guid>/posts/linux---useful-mysql-commands/</guid>
        <pubDate>Thu, 12 Feb 2026 00:00:00 UTC</pubDate>
        <description>While working on cloud server where PHPMyAdmin is not installed then using Linux terminal is the most efficient way to manage MySQL database and respective tables.
These are the all essential MySQL commands that can be executed from any Linux environment.
1. Login to MySQL Server
Login using root user:
mysql -u root -p Login with host:
mysql -u username -p -h localhost Login with port:
mysql -u username -p -P 3306 2. Database Management Commands
</description>
      </item>
    
      <item>
        <title>HTML form to Google Sheet Integration</title>
        <link>/posts/html---form-to-google-sheet-integration/</link>
        <guid>/posts/html---form-to-google-sheet-integration/</guid>
        <pubDate>Fri, 16 Jan 2026 00:00:00 UTC</pubDate>
        <description>A few days ago, in a project, the client asked to implement a feature to create a web form in HTML with file upload ability. The form submission data is needed to be stored in a Google sheet, and the uploaded file will be stored in Google Drive.
In this article I am sharing the exact process I followed.
Step 1: Prepare Google Sheet
Create a new Google Sheet (say Car Records).
</description>
      </item>
    
      <item>
        <title>Dynamic HTML sitemap in WordPress with shortcode</title>
        <link>/posts/wordpress---dynamic-html-sitemap/</link>
        <guid>/posts/wordpress---dynamic-html-sitemap/</guid>
        <pubDate>Fri, 18 Jul 2025 00:00:00 UTC</pubDate>
        <description>An HTML sitemap is a simple way to display all your website’s content in one place. It helps visitors and search engines quickly navigate your site’s structure. In this tutorial, we’ll show you how to create a WordPress shortcode that generates an HTML sitemap displaying Pages, Posts, and Custom Post Types (CPTs) – with an option to exclude certain post types you don’t want to display.
By the end, you’ll have a clean, dynamic sitemap you can insert anywhere using [html_sitemap exclude=”product,portfolio”].
</description>
      </item>
    
      <item>
        <title>GST number field to WooCommerce checkout and order emails</title>
        <link>/posts/woocommerce---gst-number-field-in-checkout-and-order-emails/</link>
        <guid>/posts/woocommerce---gst-number-field-in-checkout-and-order-emails/</guid>
        <pubDate>Fri, 23 May 2025 00:00:00 UTC</pubDate>
        <description>If you’re running a WooCommerce store in India or working with B2B clients, you may need to collect GST numbers during checkout. In this tutorial, you’ll learn how to add an optional GST number field on the WooCommerce checkout page, save it with the order, and display it in the admin panel as well as in the order confirmation emails.
Step 1: Add GST Number Field to Checkout Page Use the following code in your theme functions.php file to add a new optional field for the GST number just below the billing fields.
</description>
      </item>
    
      <item>
        <title>Product XML feed in WooCommerce for Facebook and Google Merchant</title>
        <link>/posts/woocommerce---product-xml-feed-for-facebook-and-google-merchant/</link>
        <guid>/posts/woocommerce---product-xml-feed-for-facebook-and-google-merchant/</guid>
        <pubDate>Thu, 15 May 2025 00:00:00 UTC</pubDate>
        <description>If you’re running a WooCommerce store and want to connect your products to Facebook Catalogue or Google Merchant Center, you usually rely on a plugin. However, plugins can add bloat, slow down your website, or offer limited control.
This guide shows you how to generate a dynamic XML product feed from WooCommerce without installing any plugin. The feed is fully compatible with Facebook Commerce Manager and Google Shopping, supports both simple and variable products, and includes custom attributes like size, colour, and more.Why Build Your Own Feed?
</description>
      </item>
    
      <item>
        <title>Custom YouTube feed plugin for WordPress</title>
        <link>/posts/wordpress---custom-youtube-feed-plugin/</link>
        <guid>/posts/wordpress---custom-youtube-feed-plugin/</guid>
        <pubDate>Sat, 10 May 2025 00:00:00 UTC</pubDate>
        <description>The Custom YouTube Feed plugin allows WordPress site owners to display videos from multiple YouTube channels and individual videos in an attractive grid layout. The plugin features pagination, popup video playback, and automatic caching for improved performance.
Key Features
Multiple Channel Support: Add videos from multiple YouTube channels Individual Video Support: Include specific videos by URL Responsive Grid Layout: 3-column grid that adapts to screen size Popup Video Player: Lightbox-style playback with Magnific Popup Smart Caching: 24-hour cache to reduce API calls Easy Pagination: Automatic pagination for large video collections Admin Dashboard: Simple interface for managing channels and settings Installation
</description>
      </item>
    
      <item>
        <title>Fetch data from Google Sheet and show in HTML using PHP</title>
        <link>/posts/php---google-sheet-data-integration/</link>
        <guid>/posts/php---google-sheet-data-integration/</guid>
        <pubDate>Tue, 06 May 2025 00:00:00 UTC</pubDate>
        <description>This documentation explains how to use the provided PHP code to fetch data from Google Sheets and display it in a custom layout using HTML/CSS.
Setup Instructions Step 1: Get Your Google Sheet ID Open your Google Sheet in a web browser
Look at the URL in the address bar - it will look like:
https://docs.google.com/spreadsheets/d/BmzaSyBzQ0cRTrbf_vxrB75nh8AoV3BtawPiiCQ/edit#gid=0
The long string between /d/ and /edit is your Sheet ID (in this example: BmzaSyBzQ0cRTrbf_vxrB75nh8AoV3BtawPiiCQ)
</description>
      </item>
    
      <item>
        <title>Disable comment system completely in WordPress</title>
        <link>/posts/wordpress---disable-comment-system/</link>
        <guid>/posts/wordpress---disable-comment-system/</guid>
        <pubDate>Fri, 02 May 2025 00:00:00 UTC</pubDate>
        <description>Here’s a comprehensive function to completely disable the WordPress comment system. Add this code to your theme’s functions.php file or in a custom plugin.
&amp;amp;lt;?php // Completely disable WordPress comments and related functionality function disable_comments_system() { // Disable support for comments and trackbacks in post types foreach (get_post_types() as $post_type) { if (post_type_supports($post_type, &amp;amp;#39;comments&amp;amp;#39;)) { remove_post_type_support($post_type, &amp;amp;#39;comments&amp;amp;#39;); remove_post_type_support($post_type, &amp;amp;#39;trackbacks&amp;amp;#39;); } } // Close comments on all existing posts update_option(&amp;amp;#39;close_comments_for_old_posts&amp;amp;#39;, 1); update_option(&amp;amp;#39;close_comments_days_old&amp;amp;#39;, 0); update_option(&amp;amp;#39;comment_registration&amp;amp;#39;, 1); update_option(&amp;amp;#39;default_ping_status&amp;amp;#39;, &amp;amp;#39;closed&amp;amp;#39;); update_option(&amp;amp;#39;default_comment_status&amp;amp;#39;, &amp;amp;#39;closed&amp;amp;#39;); // Redirect any comment feed requests to homepage add_action(&amp;amp;#39;template_redirect&amp;amp;#39;, function() { if (is_comment_feed()) { wp_redirect(home_url(), 301); exit; } }); // Remove comments page from admin menu add_action(&amp;amp;#39;admin_menu&amp;amp;#39;, function() { remove_menu_page(&amp;amp;#39;edit-comments.php&amp;amp;#39;); remove_submenu_page(&amp;amp;#39;options-general.php&amp;amp;#39;, &amp;amp;#39;options-discussion.php&amp;amp;#39;); }); // Remove comments links from admin bar add_action(&amp;amp;#39;wp_before_admin_bar_render&amp;amp;#39;, function() { global $wp_admin_bar; $wp_admin_bar-&amp;amp;gt;remove_menu(&amp;amp;#39;comments&amp;amp;#39;); }); // Remove dashboard comments widget add_action(&amp;amp;#39;wp_dashboard_setup&amp;amp;#39;, function() { remove_meta_box(&amp;amp;#39;dashboard_recent_comments&amp;amp;#39;, &amp;amp;#39;dashboard&amp;amp;#39;, &amp;amp;#39;normal&amp;amp;#39;); }); // Disable comments REST API endpoint add_filter(&amp;amp;#39;rest_endpoints&amp;amp;#39;, function($endpoints) { unset($endpoints[&amp;amp;#39;/wp/v2/comments&amp;amp;#39;]); unset($endpoints[&amp;amp;#39;/wp/v2/comments/(?P&amp;amp;lt;id&amp;amp;gt;[d]&#43;)&amp;amp;#39;]); return $endpoints; }); // Remove comment form completely (front-end) add_filter(&amp;amp;#39;comments_open&amp;amp;#39;, &amp;amp;#39;__return_false&amp;amp;#39;, 20, 2); add_filter(&amp;amp;#39;pings_open&amp;amp;#39;, &amp;amp;#39;__return_false&amp;amp;#39;, 20, 2); add_filter(&amp;amp;#39;comments_array&amp;amp;#39;, &amp;amp;#39;__return_empty_array&amp;amp;#39;, 10, 2); // Remove comment-reply script add_action(&amp;amp;#39;wp_enqueue_scripts&amp;amp;#39;, function() { wp_deregister_script(&amp;amp;#39;comment-reply&amp;amp;#39;); }, 100); // Remove comment form from templates add_action(&amp;amp;#39;init&amp;amp;#39;, function() { // Remove comment-reply script remove_action(&amp;amp;#39;wp_head&amp;amp;#39;, &amp;amp;#39;feed_links_extra&amp;amp;#39;, 3); // Remove comment form from wp_head remove_action(&amp;amp;#39;wp_head&amp;amp;#39;, &amp;amp;#39;feed_links&amp;amp;#39;, 2); // Remove comment form from content remove_filter(&amp;amp;#39;the_content&amp;amp;#39;, &amp;amp;#39;wpautop&amp;amp;#39;); add_filter(&amp;amp;#39;the_content&amp;amp;#39;, function($content) { if (is_singular()) { $content = preg_replace(&amp;amp;#39;/&amp;amp;lt;div[^&amp;amp;gt;]&#43;id=&amp;amp;#34;respond&amp;amp;#34;[^&amp;amp;gt;]*&amp;amp;gt;.*?&amp;amp;lt;/div&amp;amp;gt;/is&amp;amp;#39;, &amp;amp;#39;&amp;amp;#39;, $content); $content = preg_replace(&amp;amp;#39;/&amp;amp;lt;h3[^&amp;amp;gt;]&#43;id=&amp;amp;#34;reply-title&amp;amp;#34;[^&amp;amp;gt;]*&amp;amp;gt;.*?&amp;amp;lt;/h3&amp;amp;gt;/is&amp;amp;#39;, &amp;amp;#39;&amp;amp;#39;, $content); $content = preg_replace(&amp;amp;#39;/&amp;amp;lt;form[^&amp;amp;gt;]&#43;id=&amp;amp;#34;commentform&amp;amp;#34;[^&amp;amp;gt;]*&amp;amp;gt;.*?&amp;amp;lt;/form&amp;amp;gt;/is&amp;amp;#39;, &amp;amp;#39;&amp;amp;#39;, $content); } return $content; }); }); } add_action(&amp;amp;#39;init&amp;amp;#39;, &amp;amp;#39;disable_comments_system&amp;amp;#39;); // Remove comment form from theme templates (additional safety) add_filter(&amp;amp;#39;theme_page_templates&amp;amp;#39;, function($templates) { unset($templates[&amp;amp;#39;comments.php&amp;amp;#39;]); return $templates; }); // Hide comments in admin for all post types add_action(&amp;amp;#39;admin_init&amp;amp;#39;, function() { $post_types = get_post_types(); foreach ($post_types as $post_type) { if (post_type_supports($post_type, &amp;amp;#39;comments&amp;amp;#39;)) { remove_post_type_support($post_type, &amp;amp;#39;comments&amp;amp;#39;); remove_post_type_support($post_type, &amp;amp;#39;trackbacks&amp;amp;#39;); } } }); ?&amp;amp;gt; The function will:
</description>
      </item>
    
      <item>
        <title>Block HTtrack or any other web scrapper</title>
        <link>/posts/resources---block-httrack-or-web-scrapper/</link>
        <guid>/posts/resources---block-httrack-or-web-scrapper/</guid>
        <pubDate>Tue, 22 Apr 2025 00:00:00 UTC</pubDate>
        <description>There are several web scrappers tools are available by which your website can be downloaded as static files.
To block these webscrappers, just create a .htaccess file inside your website root directory and put the following code.
##Block bad bots RewriteEngine On RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] RewriteCond %{HTTP_USER_AGENT} ^Bot mailto:craftbot@yahoo.com [OR] RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR] RewriteCond %{HTTP_USER_AGENT} ^Custo [OR] RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR] RewriteCond %{HTTP_USER_AGENT} ^Download Demon [OR] RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR] RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR] RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR] RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR] RewriteCond %{HTTP_USER_AGENT} ^Express WebPictures [OR] RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR] RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR] RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR] RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR] RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR] RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR] RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR] RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR] RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR] RewriteCond %{HTTP_USER_AGENT} ^HMView [OR] RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^Image Stripper [OR] RewriteCond %{HTTP_USER_AGENT} ^Image Sucker [OR] RewriteCond %{HTTP_USER_AGENT} Indy Library [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR] RewriteCond %{HTTP_USER_AGENT} ^Internet Ninja [OR] RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR] RewriteCond %{HTTP_USER_AGENT} ^JOC Web Spider [OR] RewriteCond %{HTTP_USER_AGENT} ^larbin [OR] RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR] RewriteCond %{HTTP_USER_AGENT} ^Mass Downloader [OR] RewriteCond %{HTTP_USER_AGENT} ^MIDown tool [OR] RewriteCond %{HTTP_USER_AGENT} ^Mister PiX [OR] RewriteCond %{HTTP_USER_AGENT} uuuu7u^Navroad [OR] RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR] RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR] RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR] RewriteCond %{HTTP_USER_AGENT} ^Net Vampire [OR] RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR] RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR] RewriteCond %{HTTP_USER_AGENT} ^Offline Explorer [OR] RewriteCond %{HTTP_USER_AGENT} ^Offline Navigator [OR] RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR] RewriteCond %{HTTP_USER_AGENT} ^Papa Foto [OR] RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR] RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR] RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR] RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR] RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR] RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR] RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR] RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR] RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR] RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR] RewriteCond %{HTTP_USER_AGENT} ^Teleport Pro [OR] RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR] RewriteCond %{HTTP_USER_AGENT} ^Web Image Collector [OR] RewriteCond %{HTTP_USER_AGENT} ^Web Sucker [OR] RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR] RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR] RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR] RewriteCond %{HTTP_USER_AGENT} ^WebGo IS [OR] RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR] RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR] RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR] RewriteCond %{HTTP_USER_AGENT} ^Website eXtractor [OR] RewriteCond %{HTTP_USER_AGENT} ^Website Quester [OR] RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR] RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR] RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR] RewriteCond %{HTTP_USER_AGENT} ^Wget [OR] RewriteCond %{HTTP_USER_AGENT} ^Widow [OR] RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR] RewriteCond %{HTTP_USER_AGENT} ^Xaldon WebSpider [OR] RewriteCond %{HTTP_USER_AGENT} ^Zeus RewriteRule ^.* - [F,L] </description>
      </item>
    
      <item>
        <title>Change default sender name and sender email in WordPress form</title>
        <link>/posts/wordpress---change-default-sender-name-and-email/</link>
        <guid>/posts/wordpress---change-default-sender-name-and-email/</guid>
        <pubDate>Tue, 08 Apr 2025 00:00:00 UTC</pubDate>
        <description>When you get any email from your self hosted WordPress website, form name of that email will be WordPress which is quite annoying to you or your clients.
You can overwrite this by adding this small piece of code in the functions.php file of your theme.
function custom_wp_mail_from_name($email_from_name) { return &amp;amp;#39;Your Website Name&amp;amp;#39;; // Change this to your desired name } add_filter(&amp;amp;#39;wp_mail_from_name&amp;amp;#39;, &amp;amp;#39;custom_wp_mail_from_name&amp;amp;#39;); Also you can change the default from email id of the email generated from WordPress website by adding this another function in the functions.php file of your theme. function custom_wp_mail_from($email) { return &amp;amp;#39;no-reply@yourdomain.com&amp;amp;#39;; // Change this to your desired email } add_filter(&amp;amp;#39;wp_mail_from&amp;amp;#39;, &amp;amp;#39;custom_wp_mail_from&amp;amp;#39;); </description>
      </item>
    
      <item>
        <title>WordPress custom menu page, fetch data from custom MySQL table and export to CSV</title>
        <link>/posts/wordpress---export-mysql-table-data-to-csv/</link>
        <guid>/posts/wordpress---export-mysql-table-data-to-csv/</guid>
        <pubDate>Thu, 03 Apr 2025 00:00:00 UTC</pubDate>
        <description>To create a custom menu page in WordPress, retrieve custom table data from MySQL, and display it with the ability to export to CSV/Excel, you can follow these steps:
Step 1: Create a custom table in your WordPress database to store your data. You can use the $wpdb global variable to interact with custom tables in WordPress. Here’s an example of creating a custom table:
&amp;amp;lt;?php global $wpdb; $table_name = $wpdb-&amp;amp;gt;prefix . &amp;amp;#39;custom_data&amp;amp;#39;; $sql = &amp;amp;#34;CREATE TABLE IF NOT EXISTS $table_name ( id INT(11) NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, phone VARCHAR(20) NOT NULL, PRIMARY KEY (id) ) $charset_collate;&amp;amp;#34;; require_once(ABSPATH . &amp;amp;#39;wp-admin/includes/upgrade.php&amp;amp;#39;); dbDelta($sql); ?&amp;amp;gt; Step 2: Add the following code to your theme’s functions.php file or create a custom plugin file to define the custom menu page:
</description>
      </item>
    
      <item>
        <title>PHP script to download file from specific folder</title>
        <link>/posts/php---download-file-from-specific-folder/</link>
        <guid>/posts/php---download-file-from-specific-folder/</guid>
        <pubDate>Tue, 11 Mar 2025 00:00:00 UTC</pubDate>
        <description>Below is a simple example of a PHP script that allows you to download file from a specific folder. You can link to this PHP file with the file name as a parameter.
Create a file named download.php and add the following code:
&amp;amp;lt;?php // Specify the folder where your files are stored $folderPath = &amp;amp;#39;/path/to/your/files/&amp;amp;#39;; // Get the file name from the query parameter if (isset($_GET[&amp;amp;#39;file&amp;amp;#39;])) { $fileName = basename($_GET[&amp;amp;#39;file&amp;amp;#39;]); $filePath = $folderPath . $fileName; // Check if the file exists if (file_exists($filePath)) { // Set headers for download header(&amp;amp;#39;Content-Description: File Transfer&amp;amp;#39;); header(&amp;amp;#39;Content-Type: application/octet-stream&amp;amp;#39;); header(&amp;amp;#39;Content-Disposition: attachment; filename=&amp;amp;#34;&amp;amp;#39; . $fileName . &amp;amp;#39;&amp;amp;#34;&amp;amp;#39;); header(&amp;amp;#39;Expires: 0&amp;amp;#39;); header(&amp;amp;#39;Cache-Control: must-revalidate&amp;amp;#39;); header(&amp;amp;#39;Pragma: public&amp;amp;#39;); header(&amp;amp;#39;Content-Length: &amp;amp;#39; . filesize($filePath)); // Read the file and output it to the browser readfile($filePath); exit; } else { echo &amp;amp;#39;File not found.&amp;amp;#39;; } } else { echo &amp;amp;#39;File parameter missing.&amp;amp;#39;; } ?&amp;amp;gt; Replace ‘/path/to/your/files/’ with the actual path to the folder where your files are stored. Now, you can link to this script by providing the file name as a parameter, like this:
</description>
      </item>
    
      <item>
        <title>Upload image and PDF file using PHP</title>
        <link>/posts/php---upload-image-and-pdf-file/</link>
        <guid>/posts/php---upload-image-and-pdf-file/</guid>
        <pubDate>Mon, 10 Feb 2025 00:00:00 UTC</pubDate>
        <description>Here is a PHP script that allows users to upload image and PDF files with a maximum size of 5 MB. The uploaded files will be renamed using the current timestamp:
&amp;amp;lt;?php if ($_SERVER[&amp;amp;#34;REQUEST_METHOD&amp;amp;#34;] == &amp;amp;#34;POST&amp;amp;#34; &amp;amp;amp;&amp;amp;amp; isset($_FILES[&amp;amp;#34;file&amp;amp;#34;])) { $allowedExtensions = array(&amp;amp;#34;jpg&amp;amp;#34;, &amp;amp;#34;jpeg&amp;amp;#34;, &amp;amp;#34;png&amp;amp;#34;, &amp;amp;#34;pdf&amp;amp;#34;); $maxFileSize = 5 * 1024 * 1024; // 5 MB in bytes $targetDirectory = &amp;amp;#34;uploads/&amp;amp;#34;; $timestamp = time(); $targetFileName = $timestamp . &amp;amp;#34;_&amp;amp;#34; . basename($_FILES[&amp;amp;#34;file&amp;amp;#34;][&amp;amp;#34;name&amp;amp;#34;]); $targetPath = $targetDirectory . $targetFileName; $fileExtension = strtolower(pathinfo($targetFileName, PATHINFO_EXTENSION)); if (in_array($fileExtension, $allowedExtensions) &amp;amp;amp;&amp;amp;amp; $_FILES[&amp;amp;#34;file&amp;amp;#34;][&amp;amp;#34;size&amp;amp;#34;] &amp;amp;lt;= $maxFileSize) { if (move_uploaded_file($_FILES[&amp;amp;#34;file&amp;amp;#34;][&amp;amp;#34;tmp_name&amp;amp;#34;], $targetPath)) { echo &amp;amp;#34;File uploaded successfully.&amp;amp;#34;; } else { echo &amp;amp;#34;Error uploading file.&amp;amp;#34;; } } else { echo &amp;amp;#34;Invalid file. Allowed file types: jpg, jpeg, png, pdf. Max file size: 5 MB.&amp;amp;#34;; } } ?&amp;amp;gt; This is HTML form for file upload.
</description>
      </item>
    
      <item>
        <title>MySQL columns total and show highest totals</title>
        <link>/posts/php---get-mysql-columns-total-and-show-highest-totals/</link>
        <guid>/posts/php---get-mysql-columns-total-and-show-highest-totals/</guid>
        <pubDate>Fri, 10 Jan 2025 00:00:00 UTC</pubDate>
        <description>To get the total of a MySQL field and then select the three highest totals from the table, you can use the following PHP script:
&amp;amp;lt;?php // Assuming you have already established a MySQL connection // Retrieve the total of a field and select the three highest totals $servername = &amp;amp;#34;localhost&amp;amp;#34;; $username = &amp;amp;#34;your_username&amp;amp;#34;; $password = &amp;amp;#34;your_password&amp;amp;#34;; $dbname = &amp;amp;#34;your_database_name&amp;amp;#34;; // Create a new MySQL connection $conn = new mysqli($servername, $username, $password, $dbname); // Check the connection if ($conn-&amp;amp;gt;connect_error) { die(&amp;amp;#34;Connection failed: &amp;amp;#34; . $conn-&amp;amp;gt;connect_error); } // Prepare and execute the SQL statement to get the total and select three highest totals $sql = &amp;amp;#34;SELECT SUM(field_name) AS total FROM table_name GROUP BY field_name ORDER BY total DESC LIMIT 3&amp;amp;#34;; $result = $conn-&amp;amp;gt;query($sql); if ($result &amp;amp;amp;&amp;amp;amp; $result-&amp;amp;gt;num_rows &amp;amp;gt; 0) { echo &amp;amp;#34;Three highest totals: &amp;amp;lt;br&amp;amp;gt;&amp;amp;#34;; while ($row = $result-&amp;amp;gt;fetch_assoc()) { $total = $row[&amp;amp;#39;total&amp;amp;#39;]; echo $total . &amp;amp;#34;&amp;amp;lt;br&amp;amp;gt;&amp;amp;#34;; } } else { echo &amp;amp;#34;No records found.&amp;amp;#34;; } // Close the database connection $conn-&amp;amp;gt;close(); ?&amp;amp;gt; Make sure to replace ‘your_username’, ‘your_password’, ‘your_database_name’, ‘field_name’, and ‘table_name’ with the actual values for your MySQL configuration and table structure.
</description>
      </item>
    
      <item>
        <title>Compare any changed data of HTML table among different rows</title>
        <link>/posts/html---comparision-of-changed-data-in-table-rows/</link>
        <guid>/posts/html---comparision-of-changed-data-in-table-rows/</guid>
        <pubDate>Wed, 11 Dec 2024 00:00:00 UTC</pubDate>
        <description>In a HTML table where have multiple rows of same data with some difference in any cell. Now you want to highlight that specific cell data which is changed only.
We can achieve this using JavaScript. Here’s a basic example of how you could implement this functionality:
&amp;amp;lt;!DOCTYPE html&amp;amp;gt; &amp;amp;lt;html lang=&amp;amp;#34;en&amp;amp;#34;&amp;amp;gt; &amp;amp;lt;head&amp;amp;gt; &amp;amp;lt;meta charset=&amp;amp;#34;UTF-8&amp;amp;#34;&amp;amp;gt; &amp;amp;lt;meta name=&amp;amp;#34;viewport&amp;amp;#34; content=&amp;amp;#34;width=device-width, initial-scale=1.0&amp;amp;#34;&amp;amp;gt; &amp;amp;lt;title&amp;amp;gt;Highlight Changed Data&amp;amp;lt;/title&amp;amp;gt; &amp;amp;lt;style&amp;amp;gt; .changed { background-color: yellow; } &amp;amp;lt;/style&amp;amp;gt; &amp;amp;lt;/head&amp;amp;gt; &amp;amp;lt;body&amp;amp;gt; &amp;amp;lt;table id=&amp;amp;#34;data-table&amp;amp;#34;&amp;amp;gt; &amp;amp;lt;thead&amp;amp;gt; &amp;amp;lt;tr&amp;amp;gt; &amp;amp;lt;th&amp;amp;gt;Column 1&amp;amp;lt;/th&amp;amp;gt; &amp;amp;lt;th&amp;amp;gt;Column 2&amp;amp;lt;/th&amp;amp;gt; &amp;amp;lt;th&amp;amp;gt;Column 3&amp;amp;lt;/th&amp;amp;gt; &amp;amp;lt;/tr&amp;amp;gt; &amp;amp;lt;/thead&amp;amp;gt; &amp;amp;lt;tbody&amp;amp;gt; &amp;amp;lt;tr&amp;amp;gt; &amp;amp;lt;td&amp;amp;gt;Initial Value 1&amp;amp;lt;/td&amp;amp;gt; &amp;amp;lt;td&amp;amp;gt;Initial Value 2&amp;amp;lt;/td&amp;amp;gt; &amp;amp;lt;td&amp;amp;gt;Initial Value 3&amp;amp;lt;/td&amp;amp;gt; &amp;amp;lt;/tr&amp;amp;gt; &amp;amp;lt;tr&amp;amp;gt; &amp;amp;lt;td&amp;amp;gt;Changed Value 1&amp;amp;lt;/td&amp;amp;gt; &amp;amp;lt;td&amp;amp;gt;Changed Value 2&amp;amp;lt;/td&amp;amp;gt; &amp;amp;lt;td&amp;amp;gt;Changed Value 3&amp;amp;lt;/td&amp;amp;gt; &amp;amp;lt;/tr&amp;amp;gt; &amp;amp;lt;!-- Add more rows as needed --&amp;amp;gt; &amp;amp;lt;/tbody&amp;amp;gt; &amp;amp;lt;/table&amp;amp;gt; &amp;amp;lt;script&amp;amp;gt; window.onload = function () { const table = document.getElementById(&amp;amp;#39;data-table&amp;amp;#39;); const rows = table.getElementsByTagName(&amp;amp;#39;tr&amp;amp;#39;); for (let i = rows.length - 1; i &amp;amp;gt; 0; i--) { const currentRow = rows[i]; const previousRow = rows[i - 1]; if (!previousRow) { break; // Exit loop if no previous row (first row) } const currentCells = currentRow.getElementsByTagName(&amp;amp;#39;td&amp;amp;#39;); const previousCells = previousRow.getElementsByTagName(&amp;amp;#39;td&amp;amp;#39;); for (let j = 0; j &amp;amp;lt; currentCells.length; j&#43;&#43;) { const currentCell = currentCells[j]; const previousCell = previousCells[j]; if (currentCell.textContent !== previousCell.textContent) { currentCell.classList.add(&amp;amp;#39;changed&amp;amp;#39;); } } } }; &amp;amp;lt;/script&amp;amp;gt; &amp;amp;lt;/body&amp;amp;gt; &amp;amp;lt;/html&amp;amp;gt; This code compares each cell of each row with the corresponding cell of the previous row. If the content of a cell is different from the content of the corresponding cell in the previous row, it adds a changed class to highlight the change. Note: You can customise the appearance of the changed cells by modifying the CSS class .changed.
</description>
      </item>
    
      <item>
        <title>Export MySQL data into CSV using PHP</title>
        <link>/posts/php---export-mysql-data-to-csv/</link>
        <guid>/posts/php---export-mysql-data-to-csv/</guid>
        <pubDate>Mon, 25 Nov 2024 00:00:00 UTC</pubDate>
        <description>To fetch data from a MySQL database and export it to CSV using PHP, you can follow these steps:
&amp;amp;lt;?php // Database connection details $servername = &amp;amp;#34;localhost&amp;amp;#34;; $username = &amp;amp;#34;your_username&amp;amp;#34;; $password = &amp;amp;#34;your_password&amp;amp;#34;; $dbname = &amp;amp;#34;your_database_name&amp;amp;#34;; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn-&amp;amp;gt;connect_error) { die(&amp;amp;#34;Connection failed: &amp;amp;#34; . $conn-&amp;amp;gt;connect_error); } // Fetch data from your table $sql = &amp;amp;#34;SELECT * FROM your_table&amp;amp;#34;; $result = $conn-&amp;amp;gt;query($sql); // Check if any rows are returned if ($result-&amp;amp;gt;num_rows &amp;amp;gt; 0) { // Define CSV filename $filename = &amp;amp;#34;exported_data.csv&amp;amp;#34;; // Set headers for CSV download header(&amp;amp;#39;Content-Type: text/csv&amp;amp;#39;); header(&amp;amp;#39;Content-Disposition: attachment; filename=&amp;amp;#34;&amp;amp;#39; . $filename . &amp;amp;#39;&amp;amp;#34;&amp;amp;#39;); // Create a file pointer connected to the output stream $output = fopen(&amp;amp;#39;php://output&amp;amp;#39;, &amp;amp;#39;w&amp;amp;#39;); // Output CSV header $header = array(&amp;amp;#39;ID&amp;amp;#39;, &amp;amp;#39;Name&amp;amp;#39;, &amp;amp;#39;Email&amp;amp;#39;); fputcsv($output, $header); // Output data from rows while ($row = $result-&amp;amp;gt;fetch_assoc()) { fputcsv($output, $row); } // Close the file pointer fclose($output); } else { echo &amp;amp;#34;No data found&amp;amp;#34;; } // Close the database connection $conn-&amp;amp;gt;close(); ?&amp;amp;gt; Explanation:
</description>
      </item>
    
      <item>
        <title>Import CSV data into MySQL using PHP</title>
        <link>/posts/php---import-csv-data-into-mysql/</link>
        <guid>/posts/php---import-csv-data-into-mysql/</guid>
        <pubDate>Thu, 21 Nov 2024 00:00:00 UTC</pubDate>
        <description>Here’s a detailed example of how to import data from a CSV file into a MySQL database using PHP. The script processes each row one by one, displays a success message for each successfully inserted row, and stops the process if any error occurs, showing the error message.
Prerequisites: Ensure you have a MySQL database and table set up to store the CSV data. Adjust the database connection details and table schema as needed.
</description>
      </item>
    
      <item>
        <title>Print total of a variable inside while loop outside of the loop</title>
        <link>/posts/php---print-total-of-a-variable-inside-while-loop-outside-of-the-loop/</link>
        <guid>/posts/php---print-total-of-a-variable-inside-while-loop-outside-of-the-loop/</guid>
        <pubDate>Thu, 21 Nov 2024 00:00:00 UTC</pubDate>
        <description>To accumulate values from a MySQL query inside a while loop and then calculate the total value outside the loop, you can use a variable to store the total value while iterating through the records. Here’s an
example in PHP:
&amp;amp;lt;?php // Your database connection parameters $servername = &amp;amp;#34;localhost&amp;amp;#34;; $username = &amp;amp;#34;your_username&amp;amp;#34;; $password = &amp;amp;#34;your_password&amp;amp;#34;; $database = &amp;amp;#34;your_database&amp;amp;#34;; // Create a connection to the MySQL database $conn = new mysqli($servername, $username, $password, $database); // Check the connection if ($conn-&amp;amp;gt;connect_error) { die(&amp;amp;#34;Connection failed: &amp;amp;#34; . $conn-&amp;amp;gt;connect_error); } $totalValue = 0; // Initialize total value // Your SQL query $sql = &amp;amp;#34;SELECT value_column FROM your_table_name WHERE your_conditions&amp;amp;#34;; $result = $conn-&amp;amp;gt;query($sql); if ($result-&amp;amp;gt;num_rows &amp;amp;gt; 0) { while ($row = $result-&amp;amp;gt;fetch_assoc()) { // Access value column and accumulate the values $value = $row[&amp;amp;#39;value_column&amp;amp;#39;]; $totalValue &#43;= $value; // You can also store values in an array if needed // $valuesArray[] = $value; } echo &amp;amp;#34;Total value: $totalValue&amp;amp;#34;; // Print total value // If you stored values in an array, you can print or manipulate the array here // print_r($valuesArray); } else { echo &amp;amp;#34;No records found.&amp;amp;#34;; } // Close the database connection $conn-&amp;amp;gt;close(); ?&amp;amp;gt; This PHP script fetches records from the database, accumulates the values from a specific column (value_column), and calculates the total value by adding up these values inside the while loop. After the loop, it prints the total value obtained. If you need to store these values in an array for further processing, you can uncomment and modify the $valuesArray[] = $value; line accordingly.
</description>
      </item>
    

  </channel>
</rss>