Posts

Showing posts from April, 2022

Delete a file from upload folder in PHP

Image
  How to delete a file from upload folder   This tutorial teaches you how to delete a file/files from the specific folder using PHP. Sometimes while deleting a record from database table, you also need to delete an image/file from the uploaded folder which is   associated to that record.  For example, if you are removing a product from the table, at the same time, you also need to remove an uploaded product-image. So  For this, In PHP, there is a function called unlink().  Using unlink() function you can  remove a file from the specified folder. Retrieve the product-image from database and pass it to unlink function along with full path.   Syn: unlink ( "path_to_your_upload_directory/" . filename_with_extension. ); ex unlink ( "uploads/" . $ product_image ); Example Code delete_product,php   <?php $ product_id = $_GET [ 'pid' ];     $con  = mysqli_connect ( 'localhost' , 'root' , '' , 'productsdb' );     $SQL 1 =

How to center form using Bootstrap 4

Image
Learn How to center Form using Bootstrap 4       It is common for every designer, while creating a form, to align it in Center. To align Form in center using Bootstrap 4 , there are many ways. Method one  is, you can use bootstrap’s inbuilt classes, or you can create your own CSS class to center align the form. Here in this article, we are going to use an inbuilt class  to center align a form in Bootstrap 4. You can check out the following example. There is an inbuilt class called,  justify-content-center . Just add this class to the form div block, as shown in the given code below.  Method-1 center-form.html <!DOCTYPE html> <html> <head> <title>Coding-zon Demo How to center form in Bootstrap 4</title> <link rel= "stylesheet" href= "https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" > </head> <body> <div class = "container" > <div class = "row justify-content-center"

Import excel file into mysql in PHP

Image
  Upload Excel file and Import  it into MySQL in PHP  Create a table in some database with given code.   Download Library - extract it, rename the folder to library . Create index.php file with given code in a server. Create excelUpload.php with given code. Create db_config.php . Create one Excel file with some sample data as shown in the below image of Excel file. Create ' uploads ' folder in the same directory. Now start server, run the index.php. Upload a .xls file. If Everything is fine, Excel data inserted in the above created MySQL table - tbl_products . PHP Version:   5.5.11 Folder Structure      Query: CREATE TABLE IF NOT EXISTS `tbl_products` ( `id` int ( 11 ) NOT NULL AUTO_INCREMENT, `productname` varchar ( 100 ) DEFAULT NULL , `description` varchar ( 100 ) DEFAULT NULL , PRIMARY KEY (`id`) )     Top index.php <!DOCTYPE html> <html> <head> <title> coding-zon Demo - Upload Excel to MySQL in PHP </title> <lin

Import CSV File Into MySQL Using PHP

Image
 Learn How to Import CSV File into MySQL Database Using PHP     This article shows you how to import an uploaded CSV file into MySQL using PHP. index.php file having a form code to upload a CSV file. Once the file uploaded successfully, PHP opens it and reads the line from CSV. Each line of data separated into php variables and then inserted into MySQL table. This process continues until the last line of the CSV. Once it is finished inserting, It displays a message – " Data Inserted in database" And finally closes CSV file. In case any error in uploading, it shows "the file type not allowed" message. PHP Version 5.5.11 1. Create a table with given code in a Database. Query: CREATE TABLE IF NOT EXISTS `items` ( `id` int ( 11 ) NOT NULL AUTO_INCREMENT , `title` varchar ( 100 ) DEFAULT NULL , `description` varchar ( 100 ) DEFAULT NULL , PRIMARY KEY ( `id` ) ) ;   2. Create a following file with you database details and include it in a index.ph

Export HTML to Excel CSV Txt in PHP using JQuery

Image
  Export HTML Table Data to Excel, CSV and Text with jQuery, PHP This article shows you, how to export a static or a dynamic table to different file formats . Here we are using 3 types of files to export such as CSV, XLS and Text. In this example, we are using simple HTML that is exported to specific format when user select it from the drop-down. You can use a dynamic (using MySQL data) HTML instead of a simple static table. The below code examples show you how to implement the logic. In this file, first  you will find a drop-down, an HTML table and a jQuery code snippet. And on the top you need to link the specified links.  Download the code and run the index.php, then you will see the result as shown in a  given image below . Note: scan the code before use.      Index.php       <!DOCTYPE html> <html lang= "en" > <head>   <title> coding-zon tutorials demo </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jque