forked from rexali/one-farm-ecommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.php
80 lines (59 loc) · 1.36 KB
/
create.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
header("Content-Type: application/json; charset=UTF-8");
$ob = json_decode($_POST["x"], false);
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "farmer");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$ob->pImage=basename($ob->pImage);
class Jsn
{
public $result='result';
}
$j = new Jsn();
$output = array();
$outpt = array();
$output = array($j->result=> 'Saved successfully');
$outpt = array($j->result=> 'Failed to save');
// Attempt insert query execution
$sql = "INSERT INTO products
(
pName,
pPrice,
pImage,
pCategory,
pSubCategory,
pSummary,
pDetail,
pQuantity,
sName,
sPhone,
sAddress,
sEmail
)
VALUES
(
'$ob->pName',
'$ob->pPrice',
'$ob->pImage',
'$ob->pCategory',
'$ob->pSubCategory',
'$ob->pSummary',
'$ob->pDetail',
'$ob->pQuantity',
'$ob->sName',
'$ob->sPhone',
'$ob->sAddress',
'$ob->sEmail'
)";
if(mysqli_query($link, $sql)){
echo json_encode($output);
} else{
echo json_encode($outpt); //"ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>