PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, May 17, 2022

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

 May 17, 2022     javascript, mysql, php     No comments   

Issue

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


<?php  
session_start();

$con = mysqli_connect('localhost','root','' ,'bdd_globale') or die(mysqli_error());
$idAss=$_SESSION['idAss'];
$nomAss=$_SESSION['nomAss'];


$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'] : '';

$date=$_POST['date'];
$idsub=$_POST['idsub'];
$liste=$_POST['liste'];
$descp=isset($_POST['descp']) ? $_POST['descp'] : '';
$quantite=$_POST['quantite']; 


$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')";
$res=mysqli_query($con,$req);
     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>';   
            mysqli_close($con);   

?> 

Solution

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 : https://www.w3schools.com/php/php_ajax_php.asp

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 : https://www.w3schools.com/jquery/event_click.asp



Answered By - Shubham Dange
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing