-4
<?php 
include "../../settings.php";  
include "$basepath/includes/conn.php"; 

/*$receiptnum='';*/ 
$submittedby=''; 
$statementno=''; 
$amount=''; 
$accno=''; 
$dateofpayment='';

if(isset($_POST['submit'])) { /*$receiptnum=$_POST['receiptnum'];   */   
    $statementno=$_POST['statementno']; $amount=$_POST['amount'];   
    $accno=$_REQUEST['accountnum']; $submittedby=$_POST['submitby'];   
    $dateofpayment=$_REQUEST['dateofpayment']; }
    /*$query= "CALL newreceipt('$reciptnum','$statementno','$amount',@doj1,'$accno','$submitedby')";*/ 
    $query="INSERT into statement(statementno) VALUES('".$statementno."')"; 
    $query.="INSERT into   
          receipt(statementno,accountnum,dateofpayment,amount,submittedby)   
          VALUES('".$statementno."','".$accno."','".$dateofpayment."','".$amount."','".$submittedby."')";
    $result=mysqli_multi_query($con,$query); {  
    if($result) { 
         die ("An unexpected error , Please try again!");           
    } else {
         header('Location: receipt.php');
    }
}
?>
Dani Sancas
  • 1,365
  • 11
  • 27
user3363946
  • 45
  • 1
  • 9

1 Answers1

1

According to the official documentation, you have 2 ways to do it. Since you are not using the object oriented way, I'll nearly-copy-paste an example (from the doc, as I said) of the procedural way:

// Your queries
$query="INSERT into statement(statementno) VALUES('".$statementno."')"; 
    $query.="INSERT into   
          receipt(statementno,accountnum,dateofpayment,amount,submittedby)   
          VALUES('".$statementno."','".$accno."','".$dateofpayment."','".$amount."','".$submittedby."')";

/* execute multi query */
if (mysqli_multi_query($con, $query)) {
    do {
        /* store first result set */
        if ($result = mysqli_store_result($con)) {
            while ($row = mysqli_fetch_row($result)) {
                printf("%s\n", $row[0]); // Or whatever...
            }
            mysqli_free_result($result); // Free in order to store the next
        }
        }
    } while (mysqli_next_result($con));
}
Dani Sancas
  • 1,365
  • 11
  • 27
  • Have you tried to insert those two separately? Also, take a look to mysqli_commit: http://us1.php.net/manual/en/mysqli.commit.php This way you can avoid `multi_queries`. Look at the `Procedural style` example. – Dani Sancas Feb 28 '14 at 09:21
  • my code is perfect but it's redirect to another page but without inserting any value.... – user3363946 Feb 28 '14 at 09:31
  • 1
    You cannot say "my code is perfect but is not inserting anything". Also, you have `if($result) { die (...); }`, it should be `if(!$result) { die (...); }`. So you have at least 1 error. – Dani Sancas Feb 28 '14 at 09:38