-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_problems.php
More file actions
83 lines (72 loc) · 2.99 KB
/
add_problems.php
File metadata and controls
83 lines (72 loc) · 2.99 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
session_start();
include 'db_connect.php';
// Redirect if not logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
// Fetch categories for dropdown
$category_sql = "SELECT * FROM categories";
$categories = $conn->query($category_sql);
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'];
$difficulty_level = $_POST['difficulty_level'];
$category_id = $_POST['category_id'];
$source_link = $_POST['source_link'];
$description = $_POST['description']; // ✅ New field
$stmt = $conn->prepare("INSERT INTO problems (title, difficulty_level, category_id, source_link, description) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("ssiss", $title, $difficulty_level, $category_id, $source_link, $description);
if ($stmt->execute()) {
echo "<div class='alert alert-success text-center'>Problem added successfully!</div>";
} else {
echo "<div class='alert alert-danger text-center'>Error: " . $stmt->error . "</div>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add Problem</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
</head>
<body class="bg-light">
<div class="container mt-5">
<h2 class="mb-4">Add New Problem</h2>
<form method="post">
<div class="mb-3">
<label class="form-label">Title:</label>
<input type="text" name="title" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Difficulty:</label>
<select name="difficulty_level" class="form-select" required>
<option value="Easy">Easy</option>
<option value="Medium">Medium</option>
<option value="Hard">Hard</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Category:</label>
<select name="category_id" class="form-select" required>
<?php while ($row = $categories->fetch_assoc()): ?>
<option value="<?= $row['category_id'] ?>"><?= htmlspecialchars($row['category_name']) ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label">Source Link:</label>
<input type="url" name="source_link" class="form-control" required>
</div>
<!-- ✅ New Textarea for Description -->
<div class="mb-3">
<label class="form-label">Description (Optional):</label>
<textarea name="description" class="form-control" rows="4" placeholder="Enter additional details, approach, constraints etc..."></textarea>
</div>
<button type="submit" class="btn btn-primary">Add Problem</button>
<a href="dashboard.php" class="btn btn-secondary">Back</a>
</form>
</div>
</body>
</html>