this is my code:
<input type="text" name="text[]" />
<input type="text" name="text[]" />
<input type="text" name="text[]" />
if (!empty($_POST['text'])) {
foreach ($_POST['text'] AS $value) {
// add to the database
$sql = 'INSERT INTO tableName SET fieldName = "' . mysql_real_escape_string($value) . '"';
}
}
I want this to only insert the fields that are filled, for example if the first two inputs are filled, insert those and skip the last one which is empty.
You’re already using
empty()to check$_POSTyou can also use it to check$value