PHP Form With Conditional Fields <p>I am trying to create a PHP form to insert records into a database where the record has conditional start and end dates. I have two radio buttons setup where you can either choose: </p> <ol> <li>No End Date </li> <li>Choose a series of date and time options which are concated into start and end dates and times. </li> </ol> <p>I have Javascript set so that by default you only see the first option. The additional fields appear if you choose the second radio button. When you hit the submit button, you get the following error: </p> <blockquote> <p>Column count doesn't match value count at row 1</p> </blockquote> <p>Can anyone tell me what the see wrong in the markup? </p> <p>Here is the code for the page:</p> <pre><code>&lt;?php require_once('../Connections/mysqlconnect.php'); ?&gt; &lt;?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION &lt; 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) &amp;&amp; ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO keywords (id, station, keyword, url, target, start_date, end_date) VALUES (%s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['id'], "int"), GetSQLValueString($_POST['station'], "text"), GetSQLValueString($_POST['keyword'], "text"), GetSQLValueString($_POST['url'], "text"), GetSQLValueString($_POST['target'], "text"), GetSQLValueString($_POST['unlimited'], "text"), GetSQLValueString(date("Y-m-d H:i:s", strtotime($_POST['startDay'] . $_POST['start-hour'] . ':' . $_POST['start-minute'] . $_POST['start-meridian'])), "date"), GetSQLValueString(date("Y-m-d H:i:s", strtotime($_POST['endDay'] . $_POST['end-hour'] . ':' . $_POST['end-minute'] . $_POST['end-meridian'])), "date")); mysql_select_db($database_mysqlconnect, $mysqlconnect); $Result1 = mysql_query($insertSQL, $mysqlconnect) or die(mysql_error()); $insertGoTo = "manage.php?mess=3"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&amp;" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_mysqlconnect, $mysqlconnect); $query_Recordset1 = "SELECT * FROM keywords"; $Recordset1 = mysql_query($query_Recordset1, $mysqlconnect) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Ad Inventory:: Add New Campaign&lt;/title&gt; &lt;script type="text/javascript" src="http://yourligas.yourli.com/datepicker/jquery-ui-1.10.4.custom/js/jquery-1.10.2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://yourligas.yourli.com/datepicker/jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://yourligas.yourli.com/datepicker/jquery-ui-1.10.4.custom/js/jquery-ui-.custom.min.js"&gt;&lt;/script&gt; &lt;script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link rel="stylesheet" type="text/css" media="screen" href="http://yourligas.yourli.com/datepicker/jquery-ui-1.10.4.custom/css/ui-lightness/jquery-ui-1.10.4.custom.css"&gt; &lt;link rel="stylesheet" type="text/css" media="screen" href="http://yourligas.yourli.com/datepicker/jquery-ui-1.10.4.custom/css/ui-lightness/jquery-ui-1.10.4.custom.min.css"&gt; &lt;script&gt; $(function() { $( "#startdatepicker" ).datepicker({ showOn: "button", buttonImage: "http://yourligas.yourli.com/datepicker/jquery-ui-1.10.4.custom/development-bundle/demos/images/calendar.gif", buttonImageOnly: true, changeMonth: true, changeYear: true }); }); $(function() { $( "#enddatepicker" ).datepicker({ showOn: "button", buttonImage: "http://yourligas.yourli.com/datepicker/jquery-ui-1.10.4.custom/development-bundle/demos/images/calendar.gif", buttonImageOnly: true, changeMonth: true, changeYear: true }); }); &lt;/script&gt; &lt;style&gt; html,body{font-family:Arial, Helvetica, sans-serif;font-size:14px;margin:0 auto;background:#EFEFEF;} h1{margin-left:0;font-size:36px;} a{text-decoration:none;color:#036;font-weight:bold;font-size:16px;} a:visited{color:#036} td{ font-family: Arial, Helvetica, sans-serif; color: #585858; } tr.heading, .heading a{color:#fff; font-size:14px;font-weight:bold} tr.heading td{background:#036!important;color:#ffffff;} tr.alt td { background-color: #B9DCFF; } tr td { background-color: #D7EBFF;padding:10px; } .nav{list-style:none;margin:0;padding:0;text-align:right;} .nav li{display:inline-block;padding:0 10px;} .confirm-message{ width:800px; margin:0 auto; border:1px solid #004A0D; padding:15px; text-align:center; background-color: #B9FFC6; } .error{ color:#ff0000; font-style:italic; } &lt;/style&gt; &lt;link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;&lt;h1 align="center" style="font-size:30px;"&gt;CONNOISSEUR LI:: Keyword Management&lt;/h1&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;?php // define variables and set to empty values $campaignErr = $startdateErr = $enddateErr = ""; $campaign = $startdate = $enddate = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["campaign"])) {$campaignErr = "Please Specify a Campaign Name!";} else {$campaign = test_input($_POST["campaign"]);} if (empty($_POST["startDay"])) {$startdateErr = "Please Specify a Start Date!";} else {$startdate = test_input($_POST["startDay"]);} if (empty($_POST["endDay"])) {$enddateErr = "Please Specify an End Date!";} else {$enddate = test_input($_POST["endDay"]);} } ?&gt; &lt;form action="&lt;?php echo $editFormAction; ?&gt;" method="post" name="form1" id="form1" style="font-size:12px;"&gt; &lt;table align="center" border="0" cellpadding="10" cellspacing="0" style="margin:0 auto;"&gt; &lt;tr valign="middle"&gt; &lt;td nowrap="nowrap" align="right"&gt;Station:&lt;/td&gt; &lt;td&gt; &lt;select name="station" style="font-size:12px;"&gt; &lt;option value="WBZO" selected="selected"&gt;WBZO&lt;/option&gt; &lt;option value="WHLI"&gt;WHLI&lt;/option&gt; &lt;option value="WKJY"&gt;WKJY&lt;/option&gt; &lt;option value="WALK"&gt;WALK&lt;/option&gt; &lt;option value="WWSK"&gt;WWSK&lt;/option&gt; &lt;/select&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="middle"&gt; &lt;td nowrap="nowrap" align="right"&gt;Keyword:&lt;/td&gt; &lt;td&gt;&lt;span id="sprytextfield1"&gt; &lt;input type="text" name="keyword" value="" size="62" required="required" style="font-size:12px;" /&gt; &lt;span class="textfieldRequiredMsg"&gt;Please specify a keyword!&lt;/span&gt;&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="middle"&gt; &lt;td nowrap="nowrap" align="right"&gt;URL:&lt;/td&gt; &lt;td&gt;&lt;span id="sprytextfield1"&gt; &lt;input type="text" name="url" value="" size="62" required="required" style="font-size:12px;" maxlength="2083" /&gt; &lt;span class="textfieldRequiredMsg"&gt;Please specify a URL!&lt;/span&gt;&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="middle"&gt; &lt;td nowrap="nowrap" align="right"&gt;&lt;/td&gt; &lt;td&gt; &lt;input name="target" type="checkbox" value="blank" /&gt; Open Link in New Window? &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="middle"&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt; &lt;div&gt; &lt;input type="radio" name="schedule" value="true" class="schedule" checked="checked" /&gt; No End Date Yet&lt;br /&gt;&lt;br /&gt; &lt;input type="radio" name="schedule" value="false" class="schedule" /&gt; Schedule a Start and End Date &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="middle" id="start-schedule"&gt; &lt;td&gt;Start Date:&lt;/td&gt; &lt;td&gt; &lt;span id="sprytextfield2"&gt; &lt;input name="startDay" id="startdatepicker" style="font-size:12px;" /&gt;&lt;style&gt;.ui-datepicker-trigger{position:relative;left:3px;top:2px;}&lt;/style&gt; &amp;nbsp;&amp;nbsp;@&amp;nbsp; &lt;?php echo "&lt;select name=\"start-hour\" style='width:50px'&gt;"; $i = 1; while ( $i &lt;= 12 ) { $i = sprintf("%02d",$i); echo "&lt;option value=".$i." selected='12'&gt;".$i."&lt;/option&gt;"; $i++; } echo "&lt;/select&gt;"; echo ":&amp;nbsp;"; echo "&lt;select name=\"start-minute\" style='width:50px'&gt;"; $i = 0; while ( $i &lt;= 59 ) { $i = sprintf("%02d",$i); echo "&lt;option value=".$i."&gt;".$i."&lt;/option&gt;"; $i++; } echo "&lt;/select&gt;"; ?&gt; &amp;nbsp; &lt;select name="start-meridian" style="width:50px;font-size:12px;"&gt;&lt;option value="am" selected="selected"&gt;AM&lt;/option&gt;&lt;option value="pm"&gt;PM&lt;/option&gt;&lt;/select&gt; &lt;span class="textfieldRequiredMsg"&gt;Please specify a start date!&lt;/span&gt; &lt;span class="textfieldInvalidFormatMsg"&gt;Invalid date format. Please specify your date as mm/dd/yyyy!&lt;/span&gt; &lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="middle" id="end-schedule"&gt; &lt;td&gt;End Date:&lt;/td&gt; &lt;td&gt; &lt;span id="sprytextfield3"&gt; &lt;input name="endDay" id="enddatepicker" style="font-size:12px;" /&gt;&lt;style&gt;.ui-datepicker-trigger{position:relative;left:3px;top:2px;}&lt;/style&gt; &amp;nbsp;&amp;nbsp;@&amp;nbsp; &lt;select name="end-hour" style="width:50px"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="3"&gt;3&lt;/option&gt; &lt;option value="4"&gt;4&lt;/option&gt; &lt;option value="5"&gt;5&lt;/option&gt; &lt;option value="6"&gt;6&lt;/option&gt; &lt;option value="7"&gt;7&lt;/option&gt; &lt;option value="8"&gt;8&lt;/option&gt; &lt;option value="9"&gt;9&lt;/option&gt; &lt;option value="10"&gt;10&lt;/option&gt; &lt;option value="11" selected="selected"&gt;11&lt;/option&gt; &lt;option value="12"&gt;12&lt;/option&gt; &lt;/select&gt; &lt;?php echo ":&amp;nbsp;"; echo "&lt;select name=\"end-minute\" style='width:50px'&gt;"; $i = 0; while ( $i &lt;= 59 ) { $i = sprintf("%02d",$i); echo "&lt;option value=".$i." selected=\"59\"&gt;".$i."&lt;/option&gt;"; $i++; } echo "&lt;/select&gt;"; ?&gt; &amp;nbsp; &lt;select name="end-meridian" style="width:50px;font-size:12px;"&gt;&lt;option value="am"&gt;AM&lt;/option&gt;&lt;option value="pm" selected="selected"&gt;PM&lt;/option&gt;&lt;/select&gt; &lt;span class="textfieldRequiredMsg"&gt;Please specify an end date!&lt;/span&gt; &lt;span class="textfieldInvalidFormatMsg"&gt;Invalid date format. Please specify your date as mm/dd/yyyy!&lt;/span&gt; &lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="baseline"&gt; &lt;td nowrap="nowrap" align="right"&gt;&amp;nbsp;&lt;/td&gt; &lt;td align="right"&gt;&lt;input type="submit" value="Insert" style="font-size:14px;padding:3px 5px;" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="hidden" name="id" value="" /&gt; &lt;input type="hidden" name="MM_insert" value="form1" /&gt; &lt;/form&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p align="center"&gt;&lt;b&gt;&lt;a href="javascript: history.go(-1)"&gt;&amp;crarr; Cancel&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;script&gt; $(document).ready(function(){ $("#start-schedule").css("display","none"); $(".schedule").click(function(){ if ($('input[name=schedule]:checked').val() == "false" ) { $("#start-schedule").slideDown("fast"); //Slide Down Effect } else { $("#start-schedule").slideUp("fast"); //Slide Up Effect } }); $("#end-schedule").css("display","none"); $(".schedule").click(function(){ if ($('input[name=schedule]:checked').val() == "false" ) { $("#end-schedule").slideDown("fast"); //Slide Down Effect } else { $("#end-schedule").slideUp("fast"); //Slide Up Effect } }); }); &lt;/script&gt; &lt;script type="text/javascript"&gt; &lt;!-- var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "date", {format:"mm/dd/yyyy", validateOn:["blur"]}); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "date", {format:"mm/dd/yyyy", validateOn:["blur"]}); //--&gt; &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php mysql_free_result($Recordset1); ?&gt; </code></pre>