9951 explained code solutions for 126 technologies


php-mysqlHow to insert a null value in MySQL using PHP?


To insert a null value in MySQL using PHP, you can use the NULL keyword. For example:

$sql = "INSERT INTO table_name (column_name) VALUES (NULL)";

This will insert a NULL value into the column_name column of the table_name table.

Code explanation

  • $sql: This is a variable that holds the SQL query.
  • INSERT INTO: This is the SQL command used to insert data into a table.
  • table_name: This is the name of the table where the data will be inserted.
  • column_name: This is the name of the column where the data will be inserted.
  • VALUES: This is the keyword used to specify the values to be inserted.
  • NULL: This is the keyword used to specify a null value.

Helpful links

Edit this code on GitHub