PHP version 4.3.11
MySQL version 4.0.25-standard
I have a table that only has 2 fields id(autoinc), list(varchar). Below is the code for the form and the insert.php file. My issue is that as you can see I have 5 fields in the form. If I only input data into 1 field then the other fields are inserted into my table as empty values. What I want to happen is if nothing is input into a form field then nothing is inserted into the table. How do I go about doing this? Thanks in advance!
Form
<form action="insert.php" method="post">
<table>
<tr>
<td><input type="text" name="data1"></td>
</tr>
<tr>
<td><input type="text" name="data2"></td>
</tr>
<tr>
<td><input type="text" name="data3"></td>
</tr>
<tr>
<td><input type="text" name="data4"></td>
</tr>
<tr>
<td><input type="text" name="data5"></td>
</tr>
</table>
<input type="Submit" value="Add"><INPUT TYPE ="button" VALUE = "Cancel" onClick="confirmBox()"><SCRIPT LANGUAGE="JavaScript">
function confirmBox() { if (confirm("Cancel?")) { location.href="#";} }
</SCRIPT>
</form>
insert.php
<?
include("../../../global/dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO `table` VALUES
('','$data1'),
('','$data2'),
('','$data3'),
('','$data4'),
('','$data5')
";
mysql_query($query);
echo "Customer Added";
mysql_close();
?>