Unusual Error in excel file

November 12, 2009 Leave a comment

Today, I was exporting data from a MySQL table to an excel file via JavaScript and flash.  My column name in table were ID, first_name, last_name, title, city, state and so forth. I exported the file to my machine and opened it. I got this error.
” Excel has detected that test.xls is a SYLK file, but cannot load. Either file has errors or it is not a SYLK file format.”

I  ran Google search on error and found that SYLK is symbolic link file.  Microsoft Support gives good  explanation.
” This problem occurs when you open a text or CSV file and the first two characters of the file are the letters ID (uppercase)”

Thankfully workaround is quite simple and I changed ID to customer_ID.

Categories: Uncategorized Tags:

isset() or empty()

June 7, 2009 Leave a comment

As a novice PHP programmer, I always found input validation to be tricky. Most basic thing to check while doing validation is to make sure that user has entered something and he has not just hit the SUBMIT button. This is trickier than it seems.

Lets say you have a ‘Title’ field with minimum character length of 10 characters. What it the user submits 10 white spaces? Will your validation script handle it? Experts will suggest regular expressions. However, they are difficult to learn for a novice programmer. In this post,  we will take a look at some basic validation techniques.

trim() function strips out the white spaces from a string. It also strips tab and newline. It’s a good idea to use this function on your POST array and then validate them. This way, your filtering logic need not worry about white spaces. (Or you can use the empty function and then use trim function before you check for the size of the string.)

Lets take a look at isset() and empty(), which are often misused. isset() is a language construct and empty() is a function.  Usually calling a function is expensive than a language construct.

  1. isset(): isset returns true if the variable is set and false otherwise. It determines if the variable is set and not is not NULL. If the variable has not been set it returns false else it returns true.  If your variable contains 0(zero), then isset will return true meaning that it won’t check for zero character. Or even if you enter empty string, like white space, it will return true.  This obviously is not very useful then.
  2. empty(): empty returns true if value is empty or not set. empty considers 0 (o as integer), “0” (o as string), null, false and “”(empty string) as empty and returns true for these characters.  As you can see, empty does a good job of finding empty characters.

Thus, it’s better to use empty() if you want to find if the user actually entered anything in the form. We will take a look at some advanced input validation techniques later.

Categories: PHP Tags:
Follow

Get every new post delivered to your Inbox.