Insert value “0” for primary keys with auto increment in MySQL

In order to insert value 0 in a field that is set as primary key for a MySQL table you need to execute the following query prior to any insert query:

Now you can successfully run the insert query with 0 set as value for a primary key, without getting any error message.

Mentioning the “SESSION” variable will make sure that you do not change the sql mode globally, but if you really want to change it globally you need to execute:


Remove spaces from an input field with JavaScript

This is a small snippet to remove the spaces from an input field using JavaScript. It can be useful when you want a value without spaces, or when you want to replace the spaces from the input field with other characters.

The JavaScript code:

The input field:

The spaces will be stripped from the input field in real-time, as the user types.