-2

I'm trying to insert data into the database, it run my coding and i get output as 'SOP data Added Successfully', but the data does not get into the database.

if (isset($_SESSION['admin_id'])) 
{
    include 'databaseConnection.php';

    if (isset($_POST['add_btn']))
        {
            $sop_name = $_POST['sop_name'];
            $sop_step = $_POST['sop_step'];
            $sop_comment = $_POST['sop_comment'];
            $department_id = $_POST['department_id'];
            $admin_id = $_SESSION['admin_id'];

            $query = "SELECT * FROM sop WHERE sop_name = '$sop_name' && admin_id = '".$_SESSION['admin_id']."'";
            $result = mysqli_query($connection, $query);
            $count = mysqli_num_rows($result);

            if ($count == 1) 
            {
                echo '<script language="javascript">';
                echo 'alert("SOP Data Already Existed")';
                echo '</script>';
            }
            else
            {
                $addSOP = "INSERT INTO sop(sop_name, sop_step, sop_comment, department_id, admin_id) VALUES('$sop_name' , '$sop_step' , '$sop_comment' , '$department_id' ,'$admin_id')";
                mysqli_query($connection, $addSOP);

                echo '<script language="javascript">';
                echo "alert('SOP Data Added Succesfully'); window.location.href='dashboardOrganizationDepartment.php'";
                echo '</script>';
            }
        }

?>

I expect that the result can be post into the database, but it is not. There is also not showing any errors for me to refer.

1 Answers1

-1

Can you put some try catch within your insert query, you will get the actual error in query

try {
        $addSOP = "INSERT INTO sop(sop_name, sop_step, sop_comment, department_id, admin_id) VALUES('$sop_name' , '$sop_step' , '$sop_comment' , '$department_id' ,'$admin_id')";
                mysqli_query($connection, $addSOP);
    } catch (Exception $e) {
        die($e->getMessage());
    }
Justin J
  • 808
  • 8
  • 14