What is causing this modx error?

Sean Kimball

I have the strangest error, a simple import/export script in a modx site is causing some very strange behaviour. here is the script:

<?php
/**
 * Project: httpdocs
 * Created by: BigBlock Studios .
 * User: Sean Kimball
 * Date: 16/07/14
 * Time: 2:44 PM
 */

$remoteip = $_SERVER['REMOTE_ADDR'];

$allowedips = array('xxx.xxx.xxx.xxx','xxx.xxx.xxx.xxx');

if(!in_array($remoteip, $allowedips)){ echo 'denied'; return; }

error_reporting(E_ALL);
ini_set('display_errors', '1');

$mshost = 'xxx.xxx.xxx.xxx';
$msdb = 'msdb';
$msuser = 'msuser';
$mspass = 'mspass';

$myhost = 'xxx.xxx.xxx.xxx';
$mydb = 'mydb';
$myuser = 'myuser';
$mypass = 'mypass';
$mytable = 'modx_gssi_inventory_data';
$gatable = 'modx_gssi_inventory_gage';
$n = 100;

$query ="select TOP $n RECORDNUMBER,RESERVECUST,TAGNUMBER,ORIGINALPRICE,WIDTH,LENGTH,SCALEWGT,MINGAGE,IBLNUMBER,MILLTAGNO,VISUALDESC,FINISH,LOCATION,PONUMBER,VENDORNUMBER,STORAGETAGNO,PRODCLASS,RELEASENUMBER, PURCHASEDESC,NCTCT,STATUS,SALESDESC,CUSTOMERPONUMBER,PLANTLOCATION,LINEALFT,PIW from dbo.POInvWrk WHERE STATUS = 'A' AND RESERVECUST = ''";

$connection = mssql_pconnect($mshost, $msuser, $mspass);

if(!$connection){echo 'Could not connect to SQL server';}

if (!mssql_select_db($msdb, $connection)) {echo 'Unable to select MSSQL database!';}

$results = mssql_query($query, $connection);

// echo mssql_num_rows($results);

if (!mssql_num_rows($results)) {

    echo 'No MSSQL records found';

} else {

    $conn = mysql_connect($myhost, $myuser, $mypass);
    mysql_select_db($mydb, $conn);
    if (!$conn) { echo 'Failed to connect to MySQL'; }
    mysql_query("delete from $mytable")or die(mysql_error()."delete failed");

    while ($result = mssql_fetch_array($results, MSSQL_BOTH)) {

        $TAGNUMBER = trim(mysql_real_escape_string($result['TAGNUMBER']));
        $NCTCT = trim(mysql_real_escape_string($result['NCTCT']));
        $PRODCLASS = trim(mysql_real_escape_string($result['PRODCLASS']));
        $FINISH = trim(mysql_real_escape_string($result['FINISH']));
        $MINGAGE = trim(mysql_real_escape_string($result['MINGAGE']));
        $WIDTH = trim(mysql_real_escape_string($result['WIDTH']));
        $LENGTH = trim(mysql_real_escape_string($result['LENGTH']));
        $SCALEWGT = trim(mysql_real_escape_string($result['SCALEWGT']));
        $RESERVECUST = trim(mysql_real_escape_string($result['RESERVECUST']));
        $PONUMBER = trim(mysql_real_escape_string($result['PONUMBER']));
        $PLANTLOCATION = trim(mysql_real_escape_string($result['PLANTLOCATION']));
        $LOCATION = trim(mysql_real_escape_string($result['LOCATION']));
        $STORAGETAGNO = trim(mysql_real_escape_string($result['STORAGETAGNO']));
        $VENDORNUMBER = trim(mysql_real_escape_string($result['VENDORNUMBER']));
        $ORIGINALPRICE = trim(mysql_real_escape_string($result['ORIGINALPRICE']));
        $MILLTAGNO = trim(mysql_real_escape_string($result['MILLTAGNO']));
        $RELEASENUMBER = trim(mysql_real_escape_string($result['RELEASENUMBER']));
        $IBLNUMBER = trim(mysql_real_escape_string($result['IBLNUMBER']));
        $VISUALDESC = trim(mysql_real_escape_string($result['VISUALDESC']));
        $PURCHASEDESC = trim(mysql_real_escape_string($result['PURCHASEDESC']));
        $RECORDNUMBER = trim(mysql_real_escape_string($result['RECORDNUMBER']));
        $STATUS = trim(mysql_real_escape_string($result['STATUS']));
        $SALESDESC = trim(mysql_real_escape_string($result['SALESDESC']));
        $CUSTOMERPONUMBER = trim(mysql_real_escape_string($result['CUSTOMERPONUMBER']));
        $LINEALFT = trim(mysql_real_escape_string($result['LINEALFT']));
        $PIW = trim(mysql_real_escape_string($result['PIW']));

        $GA = mysql_query("select ga from $gatable where $MINGAGE >= min and $MINGAGE <= max;");
        echo "select ga from $gatable where $MINGAGE >= min and $MINGAGE <= max = $GA <br />";
        $timestamp = time();

        $insert = "insert into $mytable (`timestamp`,
                tag_no, classification, grade, finish,
                gage, ga, width, `length`,
                scale_wgt, cust, po_num, plant,
                location, storage_tag_no, vendor_number, original_price,
                mill_tag_no, release_number, ibl_number, visual_desc,
                purchase_desc, mssql_id, status, sales_desc,
                customer_po_num, nctct, linealft, piw)
            values (
                '$timestamp',
                '$TAGNUMBER',
                '$NCTCT',
                '$PRODCLASS',
                '$FINISH',
                '$MINGAGE',
                '$GA',
                '$WIDTH',
                '$LENGTH',
                '$SCALEWGT',
                '$RESERVECUST',
                '$PONUMBER',
                '$PLANTLOCATION',
                '$LOCATION',
                '$STORAGETAGNO',
                '$VENDORNUMBER',
                '$ORIGINALPRICE',
                '$MILLTAGNO',
                '$RELEASENUMBER',
                '$IBLNUMBER',
                '$VISUALDESC',
                '$PURCHASEDESC',
                '$RECORDNUMBER',
                '$STATUS',
                '$SALESDESC',
                '$CUSTOMERPONUMBER',
                '$NCTCT',
                '$LINEALFT',
                '$PIW'

        );";

        mysql_query($insert)or die(mysql_error()."insert failed".$insert);

    }

    //$mysqli->close();
}


?>

The problem was that it was not populating the "GA" field in the import, everything else runs fine.

The line where I echoed out the script selecting the "GA" value outputs records like this:

select ga from modx_gssi_inventory_gage where 0.182 >= min and 0.182 <= max = Resource id #10 

If I run the query against the modx_gssi_inventory_gage table, I get the expected result an integer not "Resource id #10"

  • notice that this script is not even aware of modx & should not be returning Resource Id anything.
  • it is run stand alone, nothing calls it just point a browser at the script.
  • I can run this from a domain that does not even have modx installed & it will still come back with this weirdness.

Any thoughts as to what is going on with this???

mts7

$GA = mysql_query("select ga from $gatable where $MINGAGE >= min and $MINGAGE <= max;");

That should return a resource, and it does. You need to process that result before you can use it efficiently.

$row = mysql_fetch_assoc($GA); $GA = $row['ga'];

See PHP's page about it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive