-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcwupload.php
More file actions
51 lines (42 loc) · 1.76 KB
/
cwupload.php
File metadata and controls
51 lines (42 loc) · 1.76 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
<?php
session_start();
if(isset($_FILES['image']) && isset($_FILES['file']) && isset($_POST['name']) && isset($_POST['phone']) && isset($_POST['address']) && isset($_POST['bread']) && isset($_POST['milk_per_day']) && isset($_POST['amount']) && isset($_POST['description'])) {
// Image
$image_tmp = $_FILES['image']['tmp_name'];
$image_data = file_get_contents($image_tmp);
$image_type = mime_content_type($image_tmp);
// File
$file_tmp = $_FILES['file']['tmp_name'];
$file_data = file_get_contents($file_tmp);
$file_type = mime_content_type($file_tmp);
// Other data
$name = $_POST['name'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$bread = $_POST['bread'];
$milk_per_day = $_POST['milk_per_day'];
$amount = $_POST['amount'];
$description = $_POST['description'];
// Establish database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "agriket";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert data into the database
$stmt = $conn->prepare("INSERT INTO buff_selling (image_data, image_type, file_data, file_type, name, phone, address, bread, milk_per_day, amount, description) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssssssss", $image_data, $image_type, $file_data, $file_type, $name, $phone, $address, $bread, $milk_per_day, $amount, $description);
if($stmt->execute()) {
echo "Data uploaded successfully.";
} else {
echo "Error: " . $stmt->error;
}
// Close statement and database connection
$stmt->close();
$conn->close();
}
?>