Jump to content

special trim ?


Go to solution Solved by ginerjm,

Recommended Posts

I have a script that process emails sent to a specific email address.  Depending upon what mail account my sender uses I get some troubled data coming in that I can't seem to recognize.

 

Here is the message I get from mysql when I try to do an update with the data I have extracted from the email body.

 

 

right syntax to use near '7, 3, 2, 6, 8, 0, 4, 5, 9, 1,  0, 2, 1, 8, 3, 9, 4, 6, 5, 7, 'L')

The above is an error message that mysql sends back to my script.  That little foreign character is not supposed to be there nor does it show in the email when I receive it and forward it to this mailbox/script.

 

What can I use to find these kinds of characters?  Currently my process detects the line with the numbers and does an explode on the commas to generate my values that go into the values clause of an insert query.  In this case though that foreign char gets inserted as part of one of the values.  (The values arrive in two separately identified lines with 10 nums each, hence the problem here is with one of the lines of nums beginning with the odd character.)

 

 

Link to comment
https://forums.phpfreaks.com/topic/304819-special-trim/
Share on other sites

You know the real problem here is the SQL injection, right? A query should never fail with a syntax error like that.

 

Anyway that's probably a non-breaking space in UTF-8 encoding. \xC2\xA0 I think. How you deal with it depends on your code...

Link to comment
https://forums.phpfreaks.com/topic/304819-special-trim/#findComment-1550503
Share on other sites

Ok - I modified my script to use a prepared query.  Now I get a default-ed value of '0' for the ones that have the foreign char in them.  (My prev example left out another foreign char on the very first digit - 7 - which is now posting as 0.

 

So What else can one do to a value that has a non integer in it? I am doing a filter_var on these and that is not catching it.  As in:

 

$n = filter_var($num, FILTER_SANITIZE_NUMBER_INT);
if ($n === false)
    (handle this as error and stop processing email)

Link to comment
https://forums.phpfreaks.com/topic/304819-special-trim/#findComment-1550505
Share on other sites

For what it's worth:

$n = filter_var($num, FILTER_SANITIZE_NUMBER_INT);
if ($n === false)
 {
     $ans_msg .= "Top line has bad numbers<br>";
     $ans_msg .= "Line found is:$msg<br>";
     $ans_msg .= "Email not posted<br>";
     $bad_msg = true;
     $send_cc = false;
     break;
 }

I loop thru all my incoming values and if one of them fails this test I break out of it with flags set to kill the rest of the processing.

In my case - I am not getting this error message and the value that ends up in my query is the bad one.

Link to comment
https://forums.phpfreaks.com/topic/304819-special-trim/#findComment-1550509
Share on other sites

Oh no - not trying to be difficult.  The code for getting the email, reading line by line and analyzing the numbers is in multiple places in the script.  I only focused on this final step that was trying to validate it for the forum.

 

At this point I think I am close to a solution.  I was not using filter_var properly and have written a solution (corrected my code!).  Just waiting for my host to begin responding to my ftp requests now.....

Link to comment
https://forums.phpfreaks.com/topic/304819-special-trim/#findComment-1550514
Share on other sites

  • Solution

Solved.

 

While looping thru the number lists I was not properly recognizing the results.  I was looking for a False result to indicate an error/bad value when I should have just checked the "corrected" value and replaced the original/bad one with it.

 

Now that I am doing that my process works.

 

Thanks for your interest!

Link to comment
https://forums.phpfreaks.com/topic/304819-special-trim/#findComment-1550515
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.