Jump to content

ShadowMage

Members
  • Content Count

    3,464
  • Joined

  • Last visited

Community Reputation

94 Excellent

About ShadowMage

  • Rank
    Faal Vokundovah
  • Birthday August 27

Previous Fields

  • Languages
    (X)HTML, CSS, JavaScript, PHP (though I still have much to learn)

Profile Information

  • Location
    America's dairyland

Recent Profile Visitors

57,600 profile views
  1. The problem is not data coming from an HTML form. As mentioned, memos that are entered from the intranet (the HTML forms) are functioning correctly. The problem appears when users copy/paste directly into the ERP system. To try to further clarify, memos can be entered in one of two ways. Through a form on the intranet or directly into the ERP system. Those memos that come from the intranet form are functioning fine and do not have any character encoding issues. Entering memos directly doesn't cause issues UNLESS the user copy/pastes data (from an Outlook email, for example) into the memo. The intranet and the ERP system are two separate entities, not really connected in any way except for sharing data back and forth through an ODBC connection. The intranet is of our own design and we have full control over it. As mentioned, it connects to the ERP system's database through ODBC to retrieve data and occasionally very limited writing of data to Memos and certain other similar things. The ERP system (Epicor, in case you're wondering) is not our own and we have very, very limited control of the database it uses and none over how it interacts with said database.
  2. So, first a little background on the setup/system we're running. We have an ERP system where users enter memos and notes on quotes/orders. We also have an intranet that pulls this information back out to run reports and such. The problem I'm facing, is that users are copy/pasting data into the memo text which is creating a character encoding issue. The memo text is displaying in the web browser as the black diamond with a question mark for certain specific characters (like apostrophe's). Manually typed text doesn't seem to have this issue, nor does text that comes from the intranet and is inserted into the ERP system. It is only data that's copy/pasted directly into the ERP system. How do I detect these wrongly encoded strings and display them properly? I did try to just use utf8_encode() on the text, but that changes the black diamond to a white box. I also see there is a iconv() function to convert strings to specific encodings, but it requires an input encoding, and I have no idea what the starting charset is. I found the mb_detect_encoding() function, but that gives me a fatal error. I tried to enable the mbstring extension in php.ini but that didn't seem to make any difference.
  3. ShadowMage

    Non-numeric Value

    Ok, so this is stemming from the fact that I can't get any output from PHP except errors when they occur (as described here) but since that doesn't seem to be an issue that's going to be resolved any time soon, I need to figure out how to work around it. So, I split this issue (which I also posted in the linked thread) off into it's own separate thread to see if I can resolve this particular issue. Anyway, I'm getting this error: PHP Warning: A non-numeric value encountered in ...filepath... on line 166 Line 166 looks like this: $numPieces = ($Dim['bays']*$Dim['purlins'])*$Dim['qty']; The error doesn't even tell me which of the three variables is throwing the error. Normally, this wouldn't be an issue, because I'd just print out all the variables in the equation to see what they're being set to. However, due to the previously mentioned issue, that's not possible. So, I've tried to catch this error in the following ways: try { $numPieces = ($Dim['bays']*$Dim['purlins'])*$Dim['qty']; } catch (Throwable $e) { echo "<pre>".print_r($Dim, true)."</pre>"; } and: $blnDump = false; $which = ''; if (!is_numeric($Dim['bays'])) { $blnDump = true; $which = 'bays'; } elseif (!is_numeric($Dim['purlins'])) { $blnDump = true; $which = 'purlins'; } elseif (!is_numeric($Dim['qty'])) { $blnDump = true; $which = 'qty'; } if ($blnDump) echo "$which was non-numeric:<br /><pre>".print_r($Dim, true)."</pre>"; but neither one catches the error and I just get the error printed on the page. The error prints twice, because the code above is in a function that gets called multiple times within a loop, and the issue apparently is occurring on two different iterations of the loop. And, because the code is in a loop, I can't use exit; or die(); to kill the script and print my debugging messages, because it kills the script on the first iteration of the loop. As luck would have it, the first iteration is error free and is therefore unhelpful to say the least. Please help?
  4. This is really beginning to be a problem... I've found all the division by 0 errors I had before, but I still have this guy: PHP Warning: A non-numeric value encountered in ...filepath... on line 166 Line 166 looks like this: $numPieces = ($Dim['bays']*$Dim['purlins'])*$Dim['qty']; The error doesn't even tell me which of the three variables is throwing the error. Normally, this wouldn't be an issue, because I'd just print out all the variables in the equation to see what they're being set to. However, because of the issue that started this thread, that's not possible. I've tried to catch this error in the following ways: try { $numPieces = ($Dim['bays']*$Dim['purlins'])*$Dim['qty']; } catch (Throwable $e) { echo "<pre>".print_r($Dim, true)."</pre>"; } and: $blnDump = false; $which = ''; if (!is_numeric($Dim['bays'])) { $blnDump = true; $which = 'bays'; } elseif (!is_numeric($Dim['purlins'])) { $blnDump = true; $which = 'purlins'; } elseif (!is_numeric($Dim['qty'])) { $blnDump = true; $which = 'qty'; } if ($blnDump) echo "$which was non-numeric:<br /><pre>".print_r($Dim, true)."</pre>"; but neither one catches the error and I just get the error printed on the page. The error prints twice, because the code above is in a function that gets called multiple times within a loop, and the issue apparently is occurring on two different iterations of the loop. And, because the code is in a loop, I can't use exit; or die(); to kill the script and print my debugging messages, because it kills the script on the first iteration of the loop. As luck would have it, the first iteration is error free and is therefore unhelpful to say the least.
  5. So, I'm bumping this back up because it's become an issue again. I had been working around it using die() to print out variables and such just before any offending lines, but I've encountered a situation now where that doesn't work. Consider the following: $x = 10; $y = 3; for ($z=0; $z<10; $z++) { echo "Attempt $x / $y: "; echo ($x/$y)."<br />"; $y--; } In PHP 5, I would get output as: Attempt 10 / 3: 3.33333333 Attempt 10 / 2: 5 Attempt 10 / 1: 10 Attempt 10 / 0: PHP Warning: Division by zero in C:\inetpub\major\test.php on line 37 Now, in PHP 7, I just get the error. And I can't use die() in the loop to print the "attempt..." line because the first iteration through the loop is correct and functional. I really need to figure out how to make PHP output everything again like it used to. While writing this, I thought of a workaround for the above situation. I could put a conditional to check the value of $y like this: $x = 10; $y = 3; for ($z=0; $z<10; $z++) { if ($y==0) echo "dividing by 0: $x / $y<br />"; echo "Attempt $x / $y: "; echo ($x/$y)."<br />"; $y--; } Or use a try/catch block for more complicated equations. Maybe this is best practice anyway? EDIT: Turns out a try/catch doesn't catch this error apparently... I don't know. Still seems silly to me that PHP would prevent all other output in the event of a non-fatal error.
  6. My code doesn't halt either. As mentioned, I can get multiple notices, but I get no other output besides the error notices. As an example: echo "Hello World"; echo $undefinedVar1; echo $undefinedVar2; The above code, in PHP 5, would print the "Hello World" line and then the undefined variable errors (both of them). In 7, I still get both error messages, but not the "Hello World" line. EDIT: Oh, and my error reporting level is the same in both: error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
  7. I've recently upgraded to PHP 7 from PHP 5, but I've noticed now that warnings and notices are preventing other output from being displayed. In PHP 5, if I tried to echo an undefined variable, I would get the notice in the midst of all the other output. But now, in PHP 7 it seems to just output the notice and nothing else, although I do get several notices if I have the undefined variable in a loop. This is an issue for me, because I often place echo statements around the code when I'm debugging to trace the flow of the code, but that doesn't work in PHP 7 anymore because none of my debugging statements are being printed to the screen. I can make it work and adjust my debugging procedure by placing exit calls just before the line that's generating the error, but I'm still curious if there's a INI setting or something that can change this behavior?
  8. Explicitly setting the length to 1000 seems to work as well. Looks like it's just the CAST that's doing the trick even though it's supposed to already be text. Also, good to know about the default. Although in my case that doesn't seem to apply. I've several values that are over 30 characters and they're not being truncated. Of course, that doesn't mean that the default isn't some other value that I'll discover later if/when we have longer values.
  9. So it looks like the "fix" is to CAST the fields that are causing problems. In this case, it looks like any of the 1000 character fields are causing problems. So a "fixed" query would look like this: SELECT OrderHed.OrderNum, OrderHed_UD.ShortChar06 AS 'SalesLeader', CAST(OrderHed_UD.Character01 AS varchar) AS 'JobName' FROM OrderHed INNER JOIN OrderHed_UD ON OrderHed.SysRowID = OrderHed_UD.ForeignSysRowID WHERE (OrderHed.OpenOrder = 0) Not really sure why this works, but it does. It's weird because one would think if there was a problem with the format of the field I wouldn't be able to pull it at all, but that's not true since, as described in the OP, I can run it without the alias on ShortChar06 and pull/display data from Character01 without any issues. Anyway, thanks for trying to help out!
  10. Do you have any recommended validators you prefer?
  11. I'm just going to throw some more information I discovered on here. Maybe something will spark a possible solution. I discovered that this behavior happens as soon as I add OrderHed_UD.Character01 to a query. I can pull in anything but that field. Same for Character02 and 03. Those three fields cause my queries to throw odd errors in PHP. At one point it even threw an "ambiguous column" error on a clearly defined column (it was JobHead.JobNum and there weren't even any other JobNum fields being selected). Here's the weird thing (or another one anyway): I can run these queries with the above character fields in ODBC Test Utility (its a utility built by Microsoft) and I don't get any errors at all. It displays the results, but the character fields above display their values as TRUNC: "" which I'm assuming means they were truncated to zero characters?? The character fields are all supposedly 1000 character text fields (I don't need that many that's just what was available; these were pre-created in the database for custom data).
  12. No worries. Honestly, being such a weird and inconsistent issue, I didn't expect to get an answer. A couple of quick Google searches hadn't turned anything up, so this was a shot in the dark hoping someone else may have had a similar issue. Leave it to Microsoft... 😅
  13. Of course it does. It's Microsoft. 😁 No delimiters gives the same result as using single quotes. It's really weird because I can pull the field with an alias as long as I don't have the Character01 field on there, which itself is using an alias. But it's not a matter of using multiple aliases in a query call, because some fields I can have a dozen aliases and they all work, but then they seem to reach a certain point and cease to function. I just don't know how to fully explain what's happening...
  14. If I use the backticks I get this: PHP Warning: odbc_exec(): SQL error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near '`'., SQL state 37000 in SQLExecDirect
  15. This is a really bizarre issue and I'm not sure if anyone will be able to help, but maybe someone's seen something like this before. So, I have a query: SELECT OrderHed.OrderNum, OrderHed_UD.ShortChar06 AS 'SalesLeader', OrderHed_UD.Character01 AS 'JobName' FROM OrderHed INNER JOIN OrderHed_UD ON OrderHed.SysRowID = OrderHed_UD.ForeignSysRowID WHERE (OrderHed.OpenOrder = 0) This gives me an error message: PHP Warning: odbc_fetch_array(): SQL error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'SalesLeader'., SQL state S0022 in SQLGetData (Yes, this is run in PHP) Now, if I just remove the alias from ShortChar06 OR if I entirely remove Character01, the query runs just fine. So both of these queries will run without issue: SELECT OrderHed.OrderNum, OrderHed_UD.ShortChar06, OrderHed_UD.Character01 AS 'JobName' FROM OrderHed INNER JOIN OrderHed_UD ON OrderHed.SysRowID = OrderHed_UD.ForeignSysRowID WHERE (OrderHed.OpenOrder = 0) OR SELECT OrderHed.OrderNum, OrderHed_UD.ShortChar06 AS 'SalesLeader' FROM OrderHed INNER JOIN OrderHed_UD ON OrderHed.SysRowID = OrderHed_UD.ForeignSysRowID WHERE (OrderHed.OpenOrder = 0) Any ideas what might be causing this strange behavior? I can't see anything in the syntax that would cause issues, but something is clearly not functioning. This is happening for a couple of different fields (all of which are from the _UD tables; but not all of the _UD table fields are doing it).
×
×
  • Create New...