1
+ <?php
2
+ include_once ('Connection.php ' );
3
+
4
+ if (isset ($ _REQUEST ['submit ' ])){
5
+ $ title = $ _REQUEST ['title ' ];
6
+ $ price = $ _REQUEST ['price ' ];
7
+ $ discount_price = $ _REQUEST ['discount_price ' ];
8
+ $ short_desc = $ _REQUEST ['short_desc ' ];
9
+ $ long_desc = $ _REQUEST ['long_desc ' ];
10
+ $ file_name = $ _FILES ['fileToUpload ' ]['name ' ]; // get name
11
+ move_uploaded_file ($ _FILES ["fileToUpload " ]["tmp_name " ], 'file/ ' .$ file_name );
12
+
13
+ if (isset ($ _REQUEST ['true ' ])) {
14
+ $ status = "1 " ;
15
+ }else {
16
+ $ status = "0 " ;
17
+ }
18
+
19
+ $ sql = "INSERT INTO products (title,price,discount_price,short_desc,long_desc,main_image,status) VALUES (' $ title',' $ price',' $ discount_price',' $ short_desc',' $ long_desc',' $ file_name',' $ status') " ;
20
+ $ affected_row = $ conn ->exec ($ sql );
21
+
22
+ // Calculate the remaining upload
23
+ $ totalImages = count ($ _FILES ['product_images ' ]['tmp_name ' ]);
24
+
25
+ // $remaining_uploads = $upload_limit - $num_uploaded_images;
26
+ if ($ totalImages > 8 ) {
27
+ echo "You can't upload more than 10 images. " ;
28
+ exit ;
29
+ }
30
+
31
+ $ productId = $ conn ->lastInsertId ();
32
+ echo $ productId ;
33
+ $ uploadDir = '../Model/uploads/ ' ;
34
+ foreach ($ _FILES ['product_images ' ]['tmp_name ' ] as $ key => $ tmp_name ) {
35
+ $ uploadFile = $ uploadDir . basename ($ _FILES ['product_images ' ]['name ' ][$ key ]);
36
+ move_uploaded_file ($ tmp_name , $ uploadFile );
37
+ $ stmt = $ conn ->prepare ("INSERT INTO product_images (product_id, image_path) VALUES (?, ?) " );
38
+ $ stmt ->execute ([$ productId , $ uploadFile ]);
39
+ }
40
+ echo '<script>alert("Your Prodcut add is successufully !!!")</script> ' ;
41
+
42
+ header ('location: ../View/index.php ' );
43
+ }
44
+ ?>
45
+ <!DOCTYPE html>
46
+ <html lang="en">
47
+ <head>
48
+ <meta charset="UTF-8">
49
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
50
+ <link href="https://cdn.jsdelivr.net/npm/
[email protected] /dist/css/bootstrap.min.css" rel="stylesheet">
51
+ <!-- jQuery -->
52
+ <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
53
+ <!-- Summernote CSS and JS -->
54
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote-bs4.min.css">
55
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote-bs4.min.js"></script>
56
+ <title>Insert data </title>
57
+ <style>
58
+ .h {
59
+ margin-top: 20px;
60
+ margin-left: 310px;
61
+ }
62
+
63
+ </style>
64
+ </head>
65
+ <body>
66
+ <div class="container">
67
+ <h2><a href="../View/index.php">Home Page</a></h2>
68
+ <div class="row">
69
+ <div class="col-sm-6 border h p-4 ">
70
+ <form action="" method="POST" enctype="multipart/form-data">
71
+ <h3 class="text-center mt-3">Product</h3>
72
+ <div class="row mt-4">
73
+ <div class="form-group col">
74
+ <label for="title">Product Title</label>
75
+ <input type="text" class="form-control" name="title" id="title" placeholder="Enter Product Tilte">
76
+ </div>
77
+ </div>
78
+ <div class="row mt-3">
79
+ <div class="form-group col">
80
+ <label for="price">Product Price</label>
81
+ <input type="number" class="form-control" name="price" id="price" placeholder="Enter the product Price">
82
+ </div>
83
+ <div class="form-group col">
84
+ <label for="discount_price">Discount</label>
85
+ <input type="number" class="form-control" name="discount_price" id="discount_price" placeholder="Enter discount on prodcut ">
86
+ </div>
87
+ </div>
88
+ <div class="row mt-3">
89
+ <div class="form-group col">
90
+ <label for="short_desc">Short Description</label>
91
+ <textarea class="form-control" name="short_desc" id="short_desc"cols="30" rows="5"></textarea>
92
+ </div>
93
+ </div>
94
+ <div class="row mt-3">
95
+ <div class="form-group col">
96
+ <label for="long_desc">Long Description</label>
97
+ <textarea id="summernote" name="long_desc"></textarea>
98
+ </div>
99
+ </div>
100
+ <div class="row mt-3">
101
+ <div class="form-group col">
102
+ <label for="fileToUpload">Main Image</label>
103
+ <input class="form-control" type="file" name="fileToUpload" id="fileToUpload">
104
+ </div>
105
+ </div>
106
+ <img class='card-img-top mt-2' id="preview" style='width:24%;'/>
107
+
108
+ <div class="row mt-3">
109
+ <div class="form-group col">
110
+ <label for="product_images">Multiple Images:</label>
111
+ <input type="file" class="form-control" name="product_images[]" id="product_images" multiple accept="image/*" >
112
+ </div>
113
+ </div>
114
+ <div class="row mt-5" id="image-preview-container"></div>
115
+
116
+ <div class="row mt-3">
117
+ <div class="form-group col">
118
+ <div class="form-check">
119
+ <input class="form-check-input" type="checkbox" name="true" value="" id="status" />
120
+ <label class="form-check-label" for="status">Status</label>
121
+ </div>
122
+ </div>
123
+ </div>
124
+ <div class="row">
125
+ <div class="text-center mt-4 col">
126
+ <button type="submit" class="btn btn-primary w-50" name="submit">Add Product</button>
127
+ </div>
128
+ </div>
129
+ </form>
130
+ </div>
131
+ </div>
132
+ </div>
133
+ <script src="../JS/Summer.js"></script>
134
+ <script src="../JS/Main_Preview.js"></script>
135
+ <script src="../JS/Many_Preview.js"></script>
136
+ <script src="https://cdn.jsdelivr.net/npm/
[email protected] /dist/js/bootstrap.bundle.min.js"></script>
137
+
138
+ </body>
139
+ </html>
0 commit comments