Is there any other way to execute a SQL query?

Is there any other way to execute a SQL query than by doing an “IF” everytime?


Yes. Use exceptions for errors and in most cases let php catch and handle the exception, where it will use its error related settings to control what happens with the actual error information. Your database related code will only deal with error free execution so there’s no need for any conditional logic. The exception to this rule is when inserting/updating user submitted data. In this case, your code would catch the exception, detect if a duplicate key error occurred, and set up an error message for the user about the duplicate value.

You should be using a prepared query when supplying external/unknown data to an sql query. What you have shown will allow all the data to be deleted, by injecting sql.

Your header() redirect needs an exit/die statement to stop program execution.

Sponsor our Newsletter | Privacy Policy | Terms of Service