-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_car.php
50 lines (44 loc) · 1.26 KB
/
add_car.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
<?php
session_start();
include('db_connect.php');
// Ensure only logged-in users can add cows
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
// Ensure only authorized roles can add cows
if ($_SESSION['role'] != 'employee' && $_SESSION['role'] != 'admin') {
header("Location: unauthorized.php");
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$breed = isset($_POST['breed']) ? mysqli_real_escape_string($con, $_POST['breed']) : '';
if (!empty($breed)) {
// Insert cow into tblcows
$query = "INSERT INTO tblcows (breed) VALUES ('$breed')";
if (mysqli_query($con, $query)) {
echo "Cow added successfully!";
} else {
echo "Failed to add cow. Please try again.";
}
} else {
echo "Please provide a breed.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Cow</title>
<link rel="stylesheet" href="style1.css">
</head>
<body>
<h1>Add Cow</h1>
<form method="POST">
<label for="breed">Breed:</label>
<input type="text" id="breed" name="breed" required>
<button type="submit">Add Cow</button>
</form>
</body>
</html>