This topic is locked

get the last insert id using $dal

4/24/2014 7:47:54 AM
PHPRunner General questions
U
U.M.Mbanaso author

Hi everyone

my problem how to get the last insert id, i am usind $DAL to connect to the database.

what i have seen so far is that users uses $conn which i am not.

here is the error

mysql_insert_id() expects parameter 1 to be resource, object given

here is my code

global $dal;

$lastInsert = mysql_insert_id($conn);

$custName = $values['Customer'];

$$debitAccount;

$creditAccount;

$tblCustomer = $dal->Table("customer");

$rs = $tblCustomer->Query("Fullname='$custName'");

$data = db_fetch_array($rs);

$custID = $data["CustomerID"];
$Paymentmethod = $values['PaymentMode'];

$amt = $values['PaidAmount'];

$t_amt = $values['TotalAmount'];

$transRef = $values['DucketNumber'];

$balance = $values['BalanceDue'];

$postby = $values['CreatedBy'];
if($Paymentmethod == "CREDIT"){

$creditAccount = 0.0;

$debitAccount = $t_amt;

}else{

$creditAccount =$amt;

$debitAccount =0.0;

}
//** Insert a record into another table ****
$sql = "INSERT INTO acctcustomertransaction (customerId,CustomerName,TransactionDate,DebitTransactionAmount,CreditTransactionAmount,MeansOfCreditPayment,TransactionRef,PostedBy) values ('$custID','$custName',now(),'$debitAccount','$creditAccount','$Paymentmethod','$transRef','$postby')";

CustomQuery($sql);
$Salessql = "INSERT INTO acctsales(SalesOrderId,CustomerId,CustomerName,SalesAmount,ProductAmount,BalanceAmount,CreatedBy) vaues('$lastInsert','$custID','$custName',$amy','$t_amt','$balance','$postby')";
this code is in after record added, please can i get help?

Admin 4/24/2014

A couple of things.

  1. Make sure you are adding the following in the beginning of your code:

    global $conn;
  2. mysql... functions are being deprecated in PHP and PHPRunner uses mysqli... functions whenever is possible.
    Instead of mysql_insert_id try mysqli_insert_id

    More info: http://us2.php.net/manual/en/mysqli.insert-id.php