{"id":793,"date":"2016-08-02T23:33:33","date_gmt":"2016-08-02T18:03:33","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=793"},"modified":"2026-09-10T14:20:54","modified_gmt":"2026-09-10T08:50:54","slug":"basic-insert-delete-update-database-image-upload-using-php","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/basic-insert-delete-update-database-image-upload-using-php\/","title":{"rendered":"Basic Insert, Delete, Update Database and Image Upload Using PHP"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP can be used to perform common database operations such as inserting, viewing, updating, and deleting records. It can also be used to upload images and store their file names in a database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we will explain how to perform basic <strong>INSERT, VIEW, UPDATE, and DELETE operations<\/strong> on a MySQL database using PHP, along with a basic example of image upload.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding, make sure you have:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A web server with PHP installed.<\/li>\n\n\n\n<li>MySQL database access.<\/li>\n\n\n\n<li>Basic knowledge of PHP and HTML.<\/li>\n\n\n\n<li>Permission to create a database and table.<\/li>\n\n\n\n<li>A suitable directory to store uploaded images.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create the Database and Table<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, create a database named <code>demo<\/code> and a table named <code>reg<\/code> to store the user details.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE DATABASE demo;\n\nCREATE TABLE reg (\n    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(30) NOT NULL,\n    password VARCHAR(30) NOT NULL,\n    address VARCHAR(30) NOT NULL,\n    email VARCHAR(50),\n    fathername VARCHAR(30) NOT NULL,\n    mothername VARCHAR(30) NOT NULL,\n    country VARCHAR(50),\n    state VARCHAR(30) NOT NULL,\n    city VARCHAR(50),\n    photo VARCHAR(50)\n);\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Insert Data and Upload an Image<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The INSERT operation is used to add a new record to the database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The PHP code accepts the values submitted through the form and uploads the selected image to the <code>upload<\/code> directory. The image file name is then stored in the database.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Insert code\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The HTML form should use <code>enctype=\"multipart\/form-data\"<\/code> when uploading files.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;form action=\"\" method=\"post\" enctype=\"multipart\/form-data\">\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: View Records<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The SELECT query is used to retrieve records from the database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The VIEW page fetches the records from the <code>reg<\/code> table and displays the user information in a table. It also provides <strong>Edit<\/strong> and <strong>Delete<\/strong> links for each record.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ View code\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Update Records<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The UPDATE operation is used to modify an existing record.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The record ID is passed through the URL, the existing information is retrieved, and the submitted values are used to update the corresponding record.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Edit\/Update code\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Delete Records<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The DELETE operation is used to remove a record from the database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The record ID is passed through the URL, and the corresponding record is deleted from the <code>reg<\/code> table.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Delete code\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Important Note<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The example above uses the older PHP <code>mysql_*<\/code> functions. These functions have been removed from modern PHP versions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For new applications, it is recommended to use <strong>MySQLi<\/strong> or <strong>PDO<\/strong> with prepared statements. Passwords should also be securely hashed instead of storing them as plain text.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For image uploads, validate the file type and size before saving the file to the server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we explained how to perform basic database operations using PHP, including <strong>insert, view, update, and delete<\/strong>. We also covered how to upload an image and store its file name in a database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These operations form the basic foundation of many PHP-based applications. For production applications, modern database APIs, prepared statements, password hashing, and secure file-upload validation should be used.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What are the basic database operations in PHP?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The basic database operations are <strong>INSERT, SELECT, UPDATE, and DELETE<\/strong>, commonly referred to as CRUD operations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. How can I upload an image using PHP?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An image can be uploaded using an HTML form with <code>multipart\/form-data<\/code> and PHP&#8217;s <code>$_FILES<\/code> variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Where is the uploaded image stored?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, the uploaded image is stored in the <code>upload<\/code> directory, while its file name is stored in the database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Related Article:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-drop-a-database-in-postgresql\/\">How to drop a database in postgreSQL ? &#8211; Pheonix Solutions<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-copy-a-table-from-one-database-to-another-in-mysql\/\">How to Copy a Table from One Database to Another in MySQL? &#8211; Pheonix Solutions<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Have a technology challenge or looking for the right solution for your business? Our team can help you with <strong>cloud, DevOps, development, infrastructure, design, and more<\/strong>. Feel free to reach out to our experts <a href=\"https:\/\/pheonixsolutions.com\/contact\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction PHP can be used to perform common database operations such as inserting, viewing, updating, and deleting records. It can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[],"class_list":["post-793","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-cN","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=793"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/793\/revisions"}],"predecessor-version":[{"id":11635,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/793\/revisions\/11635"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}