<?php include "../db.php"?>
<?php
$connection= new mysqli($dbhost,$dbusername,$dbpassword,$dbname);
if($_SERVER["REQUEST_METHOD"]=="POST" && isset($_POST["add_rider_btn"])){
    $name=$_POST["add_rider_name"];
    $status=$_POST["add_rider_status"];
    if(empty($name ) && empty($status)){
    session_start();
    $_SESSION["rider_add_error"]="All Fields Are Required!!";
    header("Location: ../riders.php");
    exit();
}
else{
    $addRiderQuery="INSERT INTO rider (Rider_Name,isActive) VALUES ('$name','$status')";
    session_start();
    $_SESSION["rider_add_alert"]="Rider Added Successfully!!";
        $connection->query($addRiderQuery);
        header("Location: ../riders.php");
        exit();
    }
}
if($_SERVER["REQUEST_METHOD"]=="POST" && isset($_POST["rider_edit_btn"])){
    $id=$_POST["rider_edit_id"];
    $name=$_POST["rider_edit_name"];
    $status=$_POST["rider_edit_status"];
    if(empty($name ) && empty($status)){
    session_start();
    $_SESSION["rider_add_error"]="All Fields Are Required!!";
    header("Location: ../riders.php");
    exit();
}
else{
    $editRiderQuery="UPDATE rider SET Rider_Name='$name',isActive='$status' WHERE ID='$id'";
    session_start();
    $_SESSION["rider_add_alert"]="Rider Added Successfully!!";
        $connection->query($editRiderQuery);
        header("Location: ../riders.php");
        exit();
    }
}
if(isset($_POST["id"])){
    $ID=$_POST["id"];
    $dltRiderQuery="DELETE from rider WHERE ID='$ID'";
    $connection->query($dltRiderQuery);
}
?>