#Inserting data according to the checked on checkbox
9 messages · Page 1 of 1 (latest)
@orchid vapor What have you tried so far?
Actually haven't tried anything because don't know what to do all of this data are coming from courses table now how to insert them according to the checked checkbook row
This isn’t a server to post a problem statement and get someone to write code for you, without you even bothering yourself first.
Try yourself first, then come back when you’re actually stuck, and not just because you haven’t bothered to attempt it.
// web.php
Route::get('/enroll', [DepartmentController::class, 'showEnrollForm'])->name('enroll');
Route::post('/enroll', [DepartmentController::class, 'submitEnrollForm'])->name('enroll.submit');
//form
//controller
public function submitEnrollForm(Request $request)
{
// Retrieve the form data
$sessionId = $request->input('session');
$sectionId = $request->input('section');
$courseType = $request->input('course_type');
// Retrieve the department name from the selected course
$courseId = $request->input('course');
$course = DB::table('courses')->where('id', $courseId)->first();
// Retrieve the department name from the selected course
$course = DB::table('courses')->where('id', $courseId)->first();
if($course != null) {
$deptName = $course->department_name;
// Insert the data into the database
DB::table('enrolls')->insert([
'session_name' => $sessionId,
'section_name' => $sectionId,
'course_type' => $courseType,
'dept_name' => $deptName,
]);
// Redirect the user to a success page
return redirect()->route('enrollment.success');
} else {
// Handle the case where the course is not found
return redirect()->back()->with('error', 'Course not found.');
}
}
page just refreshing after clicking on button data is not inserting