help with error handling, using $_GET

hey i have a url like this.
http://localhost:8888/webtopics/test.php?amnt=40&from=USD&to=GBP
the application is a currency converter.
the user types this part into the url to make the app work. “amnt=40&from=USD&to=GBP”
i would like to make my system neatly handle errors.
I need to make the system handle these errors ;

Code Message
1000 Required parameter is missing
1100 Parameter not recognized
2000 Currency type not recognized
2100 Currency amount must be to 2 decimal places
3000 Service currently unavailable
3100 Error in service

i would be grateful if anyone could show me how to do any of these.
Im pretty sure if i know how to do one i could work the others out.

To do this you would need to “validate” each item. This would be done differently for each error code.

As an example… Code1000 would be checked for by looking at all the parameters sent to it for missing ones.
Something like:
if (empty($_GET[‘amnt’]) || empty($_GET[‘from’]) || empty($_GET[‘to’])) {
echo “ERROR CODE: 1000 (Required parm is missing!)”;
}
if (len($_GET[‘amnt’]) >2) {
echo "ERROR CODE: 2100 (Amount too large!);
}

These are just examples, no idea if they work, but, you should get the idea.
First, you must list all your error codes (as you did) and then make a list for each of why they are errors.
Then, go to PHP.net and find out how to test for each. For currency, you can setup an array of the legal ones and search the array against what is sent as a parm. If it is found in the array, it is okay, if not, send out an error. This is a start. If you get stuck ask for more help. Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service