-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_back.php
44 lines (35 loc) · 1.53 KB
/
add_back.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
<?php
session_start();
$link = mysqli_connect("localhost", "root", "", "e-mandai");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
if(isset($_POST['addbutton'])){
$name = mysqli_real_escape_string($link, $_POST['pname']);
$price = mysqli_real_escape_string($link, $_POST['pprice']);
$quantity = mysqli_real_escape_string($link, $_POST['pquan']);
$address = mysqli_real_escape_string($link, $_POST['add']);
$city = mysqli_real_escape_string($link, $_POST['city']);
$number = mysqli_real_escape_string($link, $_POST['number']);
$pmail = mysqli_real_escape_string($link, $_POST['pemail']);
$category = mysqli_real_escape_string($link, $_POST['category']);
$farmer=$_SESSION['username'];
$file=$_FILES['pimage'];
$filename=$file['name'];
$filepath=$file['tmp_name'];
$fileerror=$file['error'];
if($fileerror==0){
$destfile='uploads/'.$filename;
move_uploaded_file($filepath,$destfile);
$sql="INSERT INTO `products` (`name`, `price`, `quantity`,`address`,`city`,`number`,`email`,`category`,`image`,`username`) VALUES ('$name','$price','$quantity','$address','$city','$number','$pmail','$category','$destfile','$farmer')";
if(mysqli_query($link,$sql)){
echo "<script>alert('Product added successfully')</script>";
header("location:farmerhome.php");
}
else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
}
?>