tomdchi Posted October 31, 2008 Share Posted October 31, 2008 (edited) I am trying to get this scipt to work with the api but something is wrong. It is supposed to loop through and find all unpaid invoices and insert the info into another table. The main problem I am having is that it is inserting the info twice. If I do not include the gateway and invoice functions it only inserts once but then does not record the payment through the api it just inserts into the new table. Any idea how I can fix this? <?php include ("../dbconnect.php"); include ("../includes/functions.php"); include ("../includes/gatewayfunctions.php"); include ("../includes/invoicefunctions.php"); $query = "SELECT inv.userid, inv.total, inv.id, inv.status, c.firstname, c.lastname, c.companyname FROM tblinvoices inv INNER JOIN tblclients c ON c.id=inv.userid AND inv.status='Unpaid'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) break; while ($data = mysql_fetch_array($result)) { $name = $data["firstname"] . " " . $data["lastname"]; $total = $data["total"]; $invoiceid = $data["id"]; $userid = $data["userid"]; $status = $data["status"]; $companyname = $data["companyname"]; $query = "SELECT fieldid, value FROM tblcustomfieldsvalues WHERE relid='$userid' AND fieldid IN(3,4)"; $result = mysql_query($query); while ($fields = mysql_fetch_array($result)) $rtemp[$data['fieldid']] = $fields['value']; $recbankacctnumber = $data['recbankacctnumber'] = $rtemp[3]; $recbankroutingnumber = $data['recbankroutingnumber'] = $rtemp[4]; $sql = "INSERT INTO tblclientpmt(transid,userid,name,routing,checking,"; $sql .= " amount,invoiceid,processed,date,companyname) "; $sql .= "VALUES('','$userid','$name','$recbankroutingnumber','$recbankacctnumber',"; $sql .= " '$total','$invoiceid',1,now(),'$companyname')"; if (!mysql_query($sql)) echo mysql_error(); $result = select_query("tblclientpmt", "", array("invoiceid" => $invoiceid)); $payments = mysql_fetch_array($result); $transid = $payments["transid"]; if (!mysql_query($sql)) echo mysql_error(); addInvoicePayment($invoiceid, $transid, $amount, "", "rapidach"); } $done = true; ?> Edited October 31, 2008 by tomdchi 0 Quote Link to comment Share on other sites More sharing options...
tomdchi Posted November 1, 2008 Author Share Posted November 1, 2008 ok, i got it to stop inserting duplicates. The if statements were causing it. 0 Quote Link to comment Share on other sites More sharing options...
jozeph Posted November 2, 2008 Share Posted November 2, 2008 What exactly you trying to do? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.