Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem my code doesnt insert data into a multiple table it only insert to one table and the rest i doesn't.

What I have tried:

PHP
//this is the main
include('database.php');
 include ('functions.php');

   if(isset($_POST['save']))
   {
       $name = mysqli_real_escape_string($con,$_POST['name']);
       $surname = mysqli_real_escape_string($con,$_POST['surname']);
       $phone = mysqli_real_escape_string($con,$_POST['phone']);
       $email = mysqli_real_escape_string($con,$_POST['email']);
       $address = mysqli_real_escape_string($con,$_POST['address']);
       $sn = mysqli_real_escape_string($con,$_POST['sn']);
       $inv = mysqli_real_escape_string($con,$_POST['inv']);
       $reseller = mysqli_real_escape_string($con,$_POST['reseller']);
       $price = mysqli_real_escape_string($con,$_POST['price']);
       $tbPrice = mysqli_real_escape_string($con,$_POST['oprice']);
       $resdate = mysqli_real_escape_string($con,$_POST['rdate']);
       $tbDate = mysqli_real_escape_string($con,$_POST['tdate']);
       $itemName = mysqli_real_escape_string($con,$_POST['item']);
      
      
       //calling function to run query
       multiquery($name,$surname,$phone,$email,$address,$sn,$tbPrice,$tbDate,$inv,$resdate,$itemName,$price,$reseller);
       
       
       /*insertClientInfo($name,$surname,$phone,$email,$address);
       
       InsertSales($sn,$tbPrice,$tbDate,$inv,$resdate);
       
       insertItem($sn,$itemName,$price);*/
       
   }

//this is the function


function multiquery($name,$surname,$phone,$email,$address,$sn,$thaboPrice,$thaboSoldDate,$invNum,$rsoldDate,$itemName,$price,$reseller)
{
    
    include('database.php');
    
    
    $sql = "INSERT INTO client(name,surname,phone,email,address) VALUES('$name','$surname','$phone','$email','$address');";
    $sql  =$sql ."INSERT INTO client_item(puch_id,client_id,serial_no,tb_price,t_date,res_date) VALUES($invNum,(SELECT client_id FROM client WHERE name ='$name'),'$sn',$thaboPrice,'$thaboSoldDate','$rsoldDate');";
     $sql = $sql ."INSERT INTO item(serial_no,item_name,price,Reseller_id) VALUES('$sn','$itemName',$price,(SELECT Reseller_id FROM reseller WHERE ResellerName ='$reseller'));";
     
     
     if(mysqli_multi_query($con,$sql))
     {
         echo "Successfuly INSERTED";
     }
     else{
         echo "Failed to insert info". mysqli_error($con);
     }
}
Posted
Updated 22-Feb-19 2:58am

1 solution

You are assuming that the second and subsequent queries succeeded, if the first one is successful. You must check the results of each query as described in PHP: mysqli::multi_query - Manual[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900