-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprjtfinal.php
More file actions
62 lines (55 loc) · 2.27 KB
/
prjtfinal.php
File metadata and controls
62 lines (55 loc) · 2.27 KB
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
<?php
// Check if the form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["image"]) && isset($_FILES["health_certificate"])) {
$name = $_POST["name"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$livestock_type = $_POST["livestock_type"];
$age = $_POST["age"];
$amount = $_POST["amount"];
$description = $_POST["description"];
// Database connection details
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "agriket";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Prepare the image data
$image = file_get_contents($_FILES["image"]["tmp_name"]);
$health_certificate = file_get_contents($_FILES["health_certificate"]["tmp_name"]);
// Insert the image data into the database
$sql = "";
switch ($livestock_type) {
case "cow":
case "buffalo":
$milk_per_day = $_POST["milk_per_day"];
$sql = "INSERT INTO cow_selling (name, phone, address, age, amount, description, milk_per_day, image, health_certificate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssisssss", $name, $phone, $address, $age, $amount, $description, $milk_per_day, $image, $health_certificate);
break;
case "goat":
case "horse":
$gender = $_POST["gender"];
$sql = "INSERT INTO ".$livestock_type."_selling (name, phone, address, age, amount, description, gender, image, health_certificate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssisssss", $name, $phone, $address, $age, $amount, $description, $gender, $image, $health_certificate);
break;
default:
echo json_encode(["msg" => "Invalid livestock type"]);
exit;
}
if ($stmt->execute()) {
echo json_encode(["msg"=>"Images uploaded successfully"]);
} else {
echo json_encode(["msg"=>"Error uploading images: " . $stmt->error]);
}
// Close connection
$stmt->close();
$conn->close();
}
?>