0

i have form within modal after submitting form it goes on .php page. so i want to prevent this from doing this. rather it should stay on the same modal. below is my php code. please let me know how to add ID of modal into header so that form will directly go onto that modal only.

<?php
include 'db.php';
if (isset($_REQUEST['insert'])) 
    {
        $contractno = $_REQUEST['contractno'];
        $doctype = $_REQUEST['doctype'];
        $contractdate = $_REQUEST['contractdate'];
        $validupto = $_REQUEST['validupto'];
        $Remark = $_REQUEST['Remark'];      


    $sql = mysqli_query($conn,"INSERT INTO `contract`(`projectId`, `contractNo`, `documentType`, `contractDate`, `action`, `contractValueBase`, `validUpto`, `remark`) VALUES ('".$contractno."','".$validupto."''".$doctype."''".$contractdate."''".$validupto."')");

        if ($sql>0) 
            {
                header('Location: contracts.php');
                echo 'data added successfully';
            }

    }
?>
amit sutar
  • 25
  • 7

1 Answers1

0

You need to use ajax if you want to stay on the same page, Follow the below post:

jQuery Ajax POST example with PHP

OR

If its ok to reload then use "get" method in url so that u can send the id through it and you can catch it on the page using $_GET["id"]

 header('Location: contracts.php?modal_id=1'); //sending modal id via header