Skip to content

how to submit two actions(forms) by the same submit btn ? (php)

I am using code given below. I want to submit two forms values and get both values on another page listeView(ajouterAideMat.php) . By this code only values of 2nd form fetched on another page and values of first form become null. So please tell me the correct way to get the value of both forms on another page.

ps: the first form is a fetched row I want to insert it with the 2nd form witch is an insertion form , but the button submit only the 2nd form and the 1st is null as i mentioned befor


$con = mysqli_connect('localhost','root','' ,'bdd_globale') or die(mysqli_error());

$ID=isset($_SESSION['numCDD']) ? $_SESSION['numCDD'] : '';
$nom=isset($_SESSION['nom']) ? $_SESSION['nom'] : '';
$prenom=isset($_SESSION['prenom']) ? $_SESSION['prenom'] : '';
$datenaissance=isset($_SESSION['datenaissance']) ? $_SESSION['datenaissance'] : '';
$lieunaissance=isset($_SESSION['lieunaissance']) ? $_SESSION['lieunaissance'] : '';
$adress=isset($_SESSION['adresse']) ? $_SESSION['adresse'] : '';
$numTel=isset($_SESSION['numTel']) ? $_SESSION['numTel'] : '';

$descp=isset($_POST['descp']) ? $_POST['descp'] : '';

$req="INSERT INTO benificieraydrstocc( idAss,nomAss,numCDD,nom,prenom,datenaissance ,lieunaissance ,adresse,numTel ,date,idsub ,typesub,description ,quantite  ) 
values('$idAss','$nomAss','$ID','$nom','$prenom','$datenaissance','$lieunaissance','$adress' ,'$numTel', '$date','$idsub','$liste','$descp','$quantite')";
     if(! $res ) { die('Could not insert data: ' .mysqli_error($con));  }
             echo '<script type="text/javascript">'; 
echo 'alert("تمت الإضافة بنجاح");'; 
echo 'window.location.href = "listeAideMat.php";';
echo '</script>';   




Provided code isn’t clear, but Yes it is possible,

Simple method would be use ajax ,prevent submit button s from submitting form and use ajax define statement /. function on click of submit button

Ref :

2.another way is worst practice ever but there is click() function in jquery, by using it you perform click event from JS, use it but with this you will get some time related issue(not recommended but worth a shot) Ref :