-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.php
More file actions
46 lines (39 loc) · 1.37 KB
/
insert.php
File metadata and controls
46 lines (39 loc) · 1.37 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
<?php
// Database connection
$con = mysqli_connect("localhost", "root", "423301", "mini");
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
// Get data from AngularJS
$data = json_decode(file_get_contents("php://input"));
// Extract values safely
$turf_name = mysqli_real_escape_string($con, $data->turf_name);
$location = mysqli_real_escape_string($con, $data->location);
$price = mysqli_real_escape_string($con, $data->price);
$availability = mysqli_real_escape_string($con, $data->availability);
$btnname = $data->btnname;
$id = isset($data->id) ? $data->id : 0;
// Insert or Update
if ($btnname == "Add") {
$query = "INSERT INTO turf (turf_name, location, price, availability)
VALUES ('$turf_name', '$location', '$price', '$availability')";
if (mysqli_query($con, $query)) {
echo "✅ Turf Added Successfully!";
} else {
echo "❌ Failed to Add Turf.";
}
}
elseif ($btnname == "Update") {
$query = "UPDATE turf
SET turf_name='$turf_name', location='$location', price='$price', availability='$availability'
WHERE id='$id'";
if (mysqli_query($con, $query)) {
echo "✅ Turf Updated Successfully!";
} else {
echo "❌ Failed to Update Turf.";
}
}
// Close connection
mysqli_close($con);
?>