-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-code.php
63 lines (49 loc) · 1.72 KB
/
upload-code.php
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
<?php
/*-- we included connection files--*/
include "connection.php";
/*--- we created a variables to display the error message on design page ------*/
$error = "";
if (isset($_POST["btn_upload"]) == "Upload")
{
$file_tmp = $_FILES["fileImg"]["tmp_name"];
$file_name = $_FILES["fileImg"]["name"];
/*image name variable that you will insert in database ---*/
$image_name = $_POST["img-name"];
$image_price = $_POST["img-price"];
$image_description = $_POST["img-description"];
//image directory where actual image will be store
$file_path = "photo/".$file_name;
/*---------------- php textbox validation checking ------------------*/
if($image_name == "")
{
$error = "Please enter Image name.";
}
if($image_price == "")
{
$error = "Please enter Image price.";
}
if($image_description == "")
{
$error = "Please enter Image description.";
}
/*-------- now insertion of image section has start -------------*/
else
{
if(file_exists($file_path))
{
$error = "Sorry,The <b>".$file_name."</b> image already exist.";
}
else
{
$result = mysqli_connect($host, $uname, $pwd) or die("Connection error: ". mysqli_error());
mysqli_select_db($result, $db_name) or die("Could not Connect to Database: ". mysqli_error());
mysqli_query($result,"INSERT INTO image_table(img_name,img_price,img_description,img_path)
VALUES('$image_name','$image_price','$image_description','$file_path')") or die ("image not inserted". mysqli_error());
move_uploaded_file($file_tmp,$file_path);
$error = "<p align=center>File ".$_FILES["fileImg"]["name"].""."<br />Image saved into Table.";
}
}
}
$product_sql ="SELECT * FROM image_table";
$product_result = mysqli_query($conn,$product_sql);
?>