Jump to content

special trim ?


ginerjm
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
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
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
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
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
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.