I am creating a new form for my jobsheet program for my workshop. I have a jobsheet work required form with 4 fields to input. These are named work1, work2, work3 and work4. It takes these and writes to the database table jobcardwork. This has two fields, jobcard and work. I want it to write only if the field is not empty as maybe not all 3 lines have text. My code is like this.
$a = array($work1, $work2, $work3, $work4);
foreach ($a as $b)
{
$sql6 = "INSERT INTO jobcardwork (Jobcard,Work)VALUES('2','$b')";
$result6=mysql_query($sql6);
}
This works but will write even if there is nothing in the box. The result is.
id jobcard work
14 2
15 2 linda
16 2 dan
as you can see, its written the first line and entered the jobcard number but there was no text in the box so it has left this null. Please help. Thanks. p.s I know mysql is old but I started writting it before mysqli and PDO. Sorry.