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 1) No End Date or 2) Choose a series of date and time options which are concated into start and end dates and times. 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: Column count doesn't match value count at row 1. Can anyone tell me what the see wrong in the markup? Here is the code for the page:
<?php require_once('../Connections/mysqlconnect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 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"])) && ($_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, '?')) ? "&" : "?";
$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);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ad Inventory:: Add New Campaign</title>
<script type="text/javascript" src="http://ift.tt/1It1GX5"></script>
<script type="text/javascript" src="http://ift.tt/1GPXmD5"></script>
<script type="text/javascript" src="http://ift.tt/1GPXodX"></script>
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" media="screen" href="http://ift.tt/1It1JlD">
<link rel="stylesheet" type="text/css" media="screen" href="http://ift.tt/1GPXoe1">
<script>
$(function() {
$( "#startdatepicker" ).datepicker({
showOn: "button",
buttonImage: "http://ift.tt/1It1GXd",
buttonImageOnly: true,
changeMonth: true,
changeYear: true
});
});
$(function() {
$( "#enddatepicker" ).datepicker({
showOn: "button",
buttonImage: "http://ift.tt/1It1GXd",
buttonImageOnly: true,
changeMonth: true,
changeYear: true
});
});
</script>
<style>
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;
}
</style>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p><h1 align="center" style="font-size:30px;">CONNOISSEUR LI:: Keyword Management</h1></p>
<p> </p>
<?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"]);}
}
?>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1" style="font-size:12px;">
<table align="center" border="0" cellpadding="10" cellspacing="0" style="margin:0 auto;">
<tr valign="middle">
<td nowrap="nowrap" align="right">Station:</td>
<td>
<select name="station" style="font-size:12px;">
<option value="WBZO" selected="selected">WBZO</option>
<option value="WHLI">WHLI</option>
<option value="WKJY">WKJY</option>
<option value="WALK">WALK</option>
<option value="WWSK">WWSK</option>
</select></td>
</tr>
<tr valign="middle">
<td nowrap="nowrap" align="right">Keyword:</td>
<td><span id="sprytextfield1">
<input type="text" name="keyword" value="" size="62" required="required" style="font-size:12px;" />
<span class="textfieldRequiredMsg">Please specify a keyword!</span></span>
</td>
</tr>
<tr valign="middle">
<td nowrap="nowrap" align="right">URL:</td>
<td><span id="sprytextfield1">
<input type="text" name="url" value="" size="62" required="required" style="font-size:12px;" maxlength="2083" />
<span class="textfieldRequiredMsg">Please specify a URL!</span></span>
</td>
</tr>
<tr valign="middle">
<td nowrap="nowrap" align="right"></td>
<td>
<input name="target" type="checkbox" value="blank" /> Open Link in New Window?
</td>
</tr>
<tr valign="middle">
<td></td>
<td>
<div>
<input type="radio" name="schedule" value="true" class="schedule" checked="checked" /> No End Date Yet<br /><br />
<input type="radio" name="schedule" value="false" class="schedule" /> Schedule a Start and End Date
</div>
</td>
</tr>
<tr valign="middle" id="start-schedule">
<td>Start Date:</td>
<td>
<span id="sprytextfield2">
<input name="startDay" id="startdatepicker" style="font-size:12px;" /><style>.ui-datepicker-trigger{position:relative;left:3px;top:2px;}</style>
@
<?php
echo "<select name=\"start-hour\" style='width:50px'>";
$i = 1;
while ( $i <= 12 ) {
$i = sprintf("%02d",$i);
echo "<option value=".$i." selected='12'>".$i."</option>";
$i++;
}
echo "</select>";
echo ": ";
echo "<select name=\"start-minute\" style='width:50px'>";
$i = 0;
while ( $i <= 59 ) {
$i = sprintf("%02d",$i);
echo "<option value=".$i.">".$i."</option>";
$i++;
}
echo "</select>";
?>
<select name="start-meridian" style="width:50px;font-size:12px;"><option value="am" selected="selected">AM</option><option value="pm">PM</option></select>
<span class="textfieldRequiredMsg">Please specify a start date!</span>
<span class="textfieldInvalidFormatMsg">Invalid date format. Please specify your date as mm/dd/yyyy!</span>
</span>
</td>
</tr>
<tr valign="middle" id="end-schedule">
<td>End Date:</td>
<td>
<span id="sprytextfield3">
<input name="endDay" id="enddatepicker" style="font-size:12px;" /><style>.ui-datepicker-trigger{position:relative;left:3px;top:2px;}</style>
@
<select name="end-hour" style="width:50px">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11" selected="selected">11</option>
<option value="12">12</option>
</select>
<?php
echo ": ";
echo "<select name=\"end-minute\" style='width:50px'>";
$i = 0;
while ( $i <= 59 ) {
$i = sprintf("%02d",$i);
echo "<option value=".$i." selected=\"59\">".$i."</option>";
$i++;
}
echo "</select>";
?>
<select name="end-meridian" style="width:50px;font-size:12px;"><option value="am">AM</option><option value="pm" selected="selected">PM</option></select>
<span class="textfieldRequiredMsg">Please specify an end date!</span>
<span class="textfieldInvalidFormatMsg">Invalid date format. Please specify your date as mm/dd/yyyy!</span>
</span>
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td align="right"><input type="submit" value="Insert" style="font-size:14px;padding:3px 5px;" /></td>
</tr>
</table>
<input type="hidden" name="id" value="" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
<p align="center"><b><a href="javascript: history.go(-1)">↵ Cancel</a></b></p>
<script>
$(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
}
});
});
</script>
<script type="text/javascript">
<!--
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"]});
//-->
</script>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Aucun commentaire:
Enregistrer un commentaire