-1

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);   

?> 
hajer
  • 3
  • 3
  • 1
    You can only submit one form at a time. – Barmar May 11 '22 at 21:30
  • i'm already using 2 sumbit (one in the 1st form witch fetch the row i want , the second must submit form1 and 2nd form and insert them in the db, so in the secand i have thes problem ) – hajer May 11 '22 at 21:32
  • Are you using JavaScript to submit something using AJAX rather than normal form submission? – Barmar May 11 '22 at 21:35
  • no just normal submit – hajer May 11 '22 at 21:53
  • Then I don't understand what you mean by "the second must submit form1 and 2nd form". LIke I said above, only one form can be submitted as a time. – Barmar May 11 '22 at 21:55
  • First off, please post both your form submission code and the PHP backend code – Ken Lee May 11 '22 at 22:15
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman May 11 '22 at 22:40
  • You have an error. [`mysqli_error()`](https://www.php.net/manual/en/mysqli.error.php) needs one argument. Please consider switching error mode on instead. [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) – Dharman May 11 '22 at 22:40

1 Answers1

0

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

Shubham Dange
  • 173
  • 13