473,322 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Strange issue with odbc_execute()

<?php

global $TABLE_GL_DATA;
global $connect;

$PREPARED_SQL = odbc_prepare($connect, "INSERT INTO $TABLE_GL_DATA
VALUES (?,?,?,?,?,?,?)");

function Generate_GL_Data()
{

global $connect;
global $TABLE_WORKING;

$query = "SELECT INVOICE, TRACKING, AMOUNT, REFERENCE, SNAME, SADD1,
SADD2, SADD3, SCITY, SSTATE, SZIP, RNAME, RADD1, RADD2, RADD3, "
."RCITY, RSTATE, RZIP FROM $TABLE_WORKING WHERE BATCHNUM = " .
$_GET["BATCH_NUMBER"];
$result = odbc_exec($connect, $query);

while (odbc_fetch_row($result)) {
Parse_Results($result);
}
odbc_commit($connect);

}

Function Parse_Results($result)
{
$INVOICE = odbc_result($result, "INVOICE");
$TRACKING = odbc_result($result, "TRACKING");

$AMOUNT = odbc_result($result, "AMOUNT");
$REFERNECES = odbc_result($result, "REFERENCE");

$SZIP = odbc_result($result, "SZIP");
$RZIP = odbc_result($result, "RZIP");
// First attempt to take any cost centers from the reference data and
use those
if ( Generate_From_ProfitCenters($REFERNECES, $INVOICE, $TRACKING,
$AMOUNT) )
return;

// Now check for order numbers in the reference field and if they
exist obtain GJ data
if (Generate_From_Orders($REFERNECES, $SZIP) )
return;

// Now check for RMA numbers in the reference field and if they exist
obtain the GJ data
if ( Generate_From_RMA($REFERNECES, $RZIP) )
return;

// For all others check if they are known Vendors (ie they exist in
the Vendor Master file)
if ( Generate_From_Known_Vendor($REFERNECES) )
return;

//Generate_Defaults($INVOICE, $TRACKING, $AMOUNT);
//return;
global $PREPARED_SQL;

// default case where were are unable to figure out what this is
refering to
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING",
"0000000000", "00000000", $AMOUNT, "U");
print_r($myarray);
$result = odbc_execute($PREPARED_SQL, $myarray );
}

function Generate_Defaults($INVOICE, $TRACKING, $AMOUNT)
{
global $PREPARED_SQL;

// default case where were are unable to figure out what this is
refering to
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING",
"0000000000", "00000000", $AMOUNT, "U");
print_r($myarray);
$result = odbc_execute($PREPARED_SQL, $myarray );
}
Function Generate_From_ProfitCenters($REFERENCES, $INVOICE, $TRACKING,
$AMOUNT)
{
global $PREPARED_SQL;

/** Regular expression to find the following
Starts with the number 1 with and contains a total of 10 digits
OR Starts with the number 1 and has the format of 1### #### ##
OR Starts with the number 1 and has the format of 1###.####.##
*/
$reg_exp = "/1\\d\\d\\d\\d\\d\\d\\d\\d\\d|1\\d\\d\\d \\d\\d\\d\\d
\\d\\d|1\\d\\d\\d\\.\\d\\d\\d\\d\\.\\d\\d/";

preg_match_all($reg_exp, $REFERENCES, $results);

$c = sizeof($results[0]);
$rand_num = rand(0, $c-1);

echo "<BR> $TRACKING $REFERENCES <BR>";
for ($i = 0; $i < $c; $i++) {
// Remove any instances of periods or spaces
$results[0][$i] = trim(str_replace(" ", "", $results[0][$i]));
$results[0][$i] = trim(str_replace(".", "", $results[0][$i]));

// We round down all partials because we'll add the remainder penny
to a random one
$partial_amount = floor($AMOUNT / $c * 100) / 100;

// Check if we're on the last found profit center AND the TOTAL
amount / number of profit centers doesn't divide evenly
// If so we have to tack on the remainder to a random portion
if ($i == $rand_num && ($AMOUNT / $c) != $partial_amount) {
$partial_amount = $AMOUNT - ($partial_amount * ($c - 1));
}

if (strpos($REFERENCES, "<p id='status'
style='display:none'>OUTGOING<p>") !== false)
$ACCOUNT = "50050000";
else
$ACCOUNT = "50106000";

$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING",
"{$results[0][$i]}", "$ACCOUNT", $partial_amount, "U");
//print_r($myarray);
$result = odbc_execute($PREPARED_SQL, $myarray );
}

if ($c > 0) // Let the application know if we found any ProfitCenters
return true;
else
return false;
}
Originally I had the code from function Generate_Defaults(..) in
Parse_Results but I was getting a very strange error message

Warning: odbc_execute() [function.odbc-execute]: SQL error:
[IBM][Client Access Express ODBC Driver (32-bit)]Wrong number of
parameters., SQL state 07001 in SQLExecute in
C:\Inetpub\Accounting\WebSys\Accounts_Payable\Frei ght_EDI\Generate_GL_Data.php
on line 110

If I comment out the code (like it is above) and use the function
Generate_Defaults(..) I don't get this error message.

Now if I do the reverse (leave the default in Parse_Results() ) and
comment out Generate_From_ProfitCenters() it works...

It almost seems like there is an issue with scope and my variable
$PREPARED_SQL

Any ideas?

Apr 6 '06 #1
0 1452

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jason | last post by:
I have two applications that I wrote that use asp and javascript source files. Recently both of these applications starting acting strange on my test box. Image icons will randomly stop showing...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
3
by: Sebastian C. | last post by:
Hello everybody Since I upgraded my Office XP Professional to SP3 I got strange behaviour. Pieces of code which works for 3 years now are suddenly stop to work properly. I have Office XP...
2
by: Joneleth | last post by:
Hi I was writing some aspx pages when i experimented a strange issue. I have a div tag like this: <div id="divCourses1" style="<%=GetDisplayStyle(eidlevel, arrIdLevel)%>"> Now, as long as i...
5
by: Ian | last post by:
Hi everyone, I have found some bizarre (to me...!) behaviour of the Form_Activate function. I have a form which has a button control used to close the form and a subform with a datasheet view...
2
by: BinaryMonk | last post by:
Ok, this makes absolutely no sense to me, so I am hoping that someone here will have run across this issue as well. I have a pretty simple PHP script. which essentially just selects and displays...
3
by: Vish4u | last post by:
Hello Everyone, I have a encountered a strange issue with the execution of my stored procedure on clients machine. My stored procedure contains a cursor in which there is a select statement...
3
by: Max Vit | last post by:
I have come across a strange issue whilst trying to use a shell command call from Access and have spent some time trying to figure this out but can't find the cause as yet. The issue is: I need...
2
by: scdowney | last post by:
First and foremost, thank you in advance for any attempts to help me out. I am working on a project with work, and it requires I use CSS selectors to locate elements within a webpage. For the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.