Redirect to index.php if query forms error

Hey…using htaccess redirect im passing $lang, which subsequent pulls down specific db content.

If i have webpage.com/en or webpage.com/fr everything is fine as my query is SELECT menu.title_“.$lang.”, menu.text_“.$lang.” etc etc.

If a passed variable isnt part of the db structure then obviously it fails, as for example, menu.title_strangetext doesn’t exist.

Is there a way to redirect to index.php rather than echoing Unkown column 'menu.title_strangetext '?

Thanks in advance

Don’t you have somewhere that contains a list of which language codes are supported in your database? If not, and they’re hard-coded (as it sounds like they are, if you use column names to get each language text item) then surely a quick check at the start of the code to default to a language if the specified one does not exist, is the way?

I must admit I’d have done the database layout differently myself. I’m no expert, but it just seems easier to me to be able to run the query along the lines of “select menu_title, menu_text from displaytext where language_code = $lang” and check for getting zero results. Adding support for an extra language would be easier as well - no need to add columns for the extra language, no need to change your error checking.

Instead of redirecting to index.php, I think I’d be tempted to just pick a default language and use that, if the user somehow specifies a language code you don’t support.

Hey droop, i get your point…its something that ive done a few times and got stuck with a suppose…ill certainly consider the structure for the next project…

In the end, ive created an array of the langs, and if not valid, then redirect prior to the query.

That’s pretty much all you can do. Although I think I’d still just default it to “en” (or whatever your default local language is) rather than redirecting. But I guess that depends on the site.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.