By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
LahbabiGuideLahbabiGuide
  • الرئيسية
  • مزيج مِن أفكاري
    • مقالاتي
    • قصص قصيرة
    • سيناريوهات أفلام قصيرة
    • نصوص مسرحية قصيرة
  • أفكار المشاريع
  • قصص النجاح
  • أخبار تقنية
  • القرأن الكريم
Search
  • Advertise
© 2022 Zakariaelahbabi.com . Company. All Rights Reserved.
Reading: Upload Image In PHP With MySQL Database | Web Dev Trick
Share
Notification Show More
Latest News
bootstrap-clean-buttons-with-hover-effect-|-plain-button-ui-kit
Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit
Bootstrap
bootstrap-datatable-with-sort,-pagination,-and-search-|-sorting-data-table
Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table
Bootstrap
bootstrap-tooltip-progress-bar-animation-|-percentage-values-in-tooltip
Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip
Bootstrap
php-age-calculator-program-|-calculate-age-in-php
PHP Age Calculator Program | Calculate Age In PHP
PHP
generate-random-numbers-in-php-|-numbers-in-sort-by-order
Generate Random Numbers In PHP | Numbers In Sort By Order
PHP
Aa
LahbabiGuideLahbabiGuide
Aa
  • مزيج مِن أفكاري
  • أخبار تقنية
  • تطوير الويب
  • أفكار المشاريع
Search
  • Home
    • Home 1
    • Default Home 2
    • Default Home 3
    • Default Home 4
    • Default Home 5
  • Categories
    • تطوير الويب
    • أخبار تقنية
    • أفكار المشاريع
    • مزيج مِن أفكاري
    • قصص النجاح
  • Bookmarks
  • More Foxiz
    • Sitemap
Follow US
  • Advertise
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
upload-image-in-php-with-mysql-database-|-web-dev-trick
LahbabiGuide > تطوير الويب > PHP > Upload Image In PHP With MySQL Database | Web Dev Trick
PHP

Upload Image In PHP With MySQL Database | Web Dev Trick

admin
Last updated: 2023/03/11 at 7:37 صباحًا
By admin
Share
3 Min Read
SHARE

Upload Image In PHP, With MySQL Database: Nowadays we are on social networks, and we upload DP Stories etc. Ever wondered how this photo is uploaded in the database. After that, we can see images which are coming out of the database. So, Today we will learn how to upload image in database using PHP & MySQL.  Basically, In this tutorial, we will create a form with two inputs. First, for image upload, the second one is to write some text with an image. When someone selects an image write some text & click on the upload button, the image name and text will be upload in MySQL database. And PHP grabs image file and save it in a folder. 

Contents
Upload Image In PHP TutorialSource Code

You May Also Like

Build a Simple Quiz In PHP | Source Code

Domain Availability Checker In PHP | Get Source Code

More.

Upload Image In PHP Tutorial

Firstly,  Create a MySQL database named “image_upload” & create a table named “images”.  You can give a custom name for database and tables but, then you have to changes database & table name in PHP file too.  If you have good knowledge in PHP then it’s ok Otherwise, just follow my steps.

Create a database named “image_upload” & click on the database you have created now. Then go to SQL menu and paste these code & click on go.

CREATE TABLE `images` (

  `id` int(11) NOT NULL,

  `image` varchar(100) NOT NULL,

  `image_text` text NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Now you have successfully created a database for this program. Now Create a file named “index.php” & a folder named “images” in the same destination where you saved index.php file. Now let me explain some important things about this program: I had created a form with method=”POST” and put on action index.php (action=”index.php”) file. You can create another file for PHP I had put everything in a single file. More info about PHP Method.

Note: Make sure you put enctype=”multipart/form-data” in form. Example (

), And don’t forget to create “images” folder. Otherwise, this program will not work.

Source Code

Open “index.php” file you had created before and paste these codes give below:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

<!— Code By WebDevTrick ( https://webdevtrick.com ) –>

  $db = mysqli_connect(“localhost”, “root”, “”, “image_upload”);

  $msg = “”;

  if (isset($_POST[‘upload’])) {

   $image = $_FILES[‘image’][‘name’];

   $image_text = mysqli_real_escape_string($db, $_POST[‘image_text’]);

   $target = “http://webdevtrick.com/images/”.basename($image);

   $sql = “INSERT INTO images (image, image_text) VALUES (‘$image’, ‘$image_text’)”;

   mysqli_query($db, $sql);

   if (move_uploaded_file($_FILES[‘image’][‘tmp_name’], $target)) {

   $msg = “Image uploaded successfully”;

   }else{

   $msg = “Failed to upload image”;

   }

  }

  $result = mysqli_query($db, “SELECT * FROM images”);

?>

<!DOCTYPE html>

<html>

<head>

<title>Image Upload</title>

</head>

<body>

<div id=“content”>

  

    while ($row = mysqli_fetch_array($result)) {

      echo “

“;

       echo “.$row[‘image’].“‘ >”;

       echo “

“.$row[‘image_text’].“

“;

      echo “

“;

    }

  ?>

  <form  method=“POST”  action=“index.php” enctype=“multipart/form-data”>

   <input type=“hidden” name=“size” value=“1000000”>

   <div>

     <input type=“file” name=“image”>

   </div>

   <div>

      <textarea

       id=“text”

       cols=“40”

       rows=“4”

       name=“image_text”

       placeholder=“What’s In Your Mind?”></textarea>

   </div>

   <div>

   <button type=“submit” name=“upload”>Upload</button>

   </div>

  </form>

</div>

</body>

</html>

That’s It. Now you have successfully created image upload in PHP & MySQL program. This a very basic program, I created this for those people who are beginners and want to learn. In the future, I will share advance PHP programs also. If You have any question or doubt comment down below.

Thanks For Visiting, Keep Visiting.

You Might Also Like

PHP Age Calculator Program | Calculate Age In PHP

Generate Random Numbers In PHP | Numbers In Sort By Order

PHP Shopping Cart | Add to Cart Feature In PHP & MySQL

New Years Countdown Timer With jQuery and Bootstrap Layout | Time Left

PHP Calculator Example With Source Code | Basic Calculator in PHP

TAGGED: image upload php, PHP, php and mysql, php source code, php tutorial, Web Development
admin مارس 11, 2023
Share this Article
Facebook Twitter Pinterest Whatsapp Whatsapp LinkedIn Tumblr Reddit VKontakte Telegram Email Copy Link Print
Previous Article bootstrap-tooltip-progress-bar-animation-|-percentage-values-in-tooltip Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip
Next Article bootstrap-datatable-with-sort,-pagination,-and-search-|-sorting-data-table Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table
Leave a comment Leave a comment

اترك تعليقاً إلغاء الرد

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *

Stay Connected

235.3k Followers Like
69.1k Followers Follow
11.6k Followers Pin
56.4k Followers Follow
136k Subscribers Subscribe
4.4k Followers Follow
- Advertisement -
Ad imageAd image

Latest News

bootstrap-clean-buttons-with-hover-effect-|-plain-button-ui-kit
Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit
Bootstrap مارس 11, 2023
bootstrap-datatable-with-sort,-pagination,-and-search-|-sorting-data-table
Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table
Bootstrap مارس 11, 2023
bootstrap-tooltip-progress-bar-animation-|-percentage-values-in-tooltip
Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip
Bootstrap مارس 11, 2023
php-age-calculator-program-|-calculate-age-in-php
PHP Age Calculator Program | Calculate Age In PHP
PHP مارس 11, 2023
//

We influence 20 million users and is the number one business and technology news network on the planet

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

[mc4wp_form id=”847″]

LahbabiGuideLahbabiGuide
Follow US

© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.

Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc..

[mc4wp_form]
Zero spam, Unsubscribe at any time.

Removed from reading list

Undo
Welcome Back!

Sign in to your account

Lost your password?