Daniel Yantis Daniel Yantis - 3 months ago 11
MySQL Question

Error: 1136 : Column count doesn't match value count at row 1 - BUT WHY?

I had this all working then added 7 fields to the form and sql now not working. Error: 1136 : Column count doesn't match value count at row 1.

Yah, I know what it means but i can't seem to locate the mismatch.
Maybe more eyes on the code will help - i've been looking at this all night.

Form:

<form id="registration" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<fieldset>
<legend><h1>Registration</h1></legend>
<label for="entrynum">Entry Number</label>
<input type="number" pattern="\d*" name="entrynum" id="entrynum" value="" required="true" placeholder="" autofocus onchange="entry_check()" />

<label for="fname">First Name</label>
<input type="text" name="fname" id="fname" value="" required="true" placeholder="" list="" style="text-transform:capitalize" onkeyup="javascript:this.value=this.value.charAt(0).toUpperCase() + this.value.substr(1);" />

<label for="lname">Last Name</label>
<input type="text" name="lname" id="lname" value="" required="true" placeholder="" list="" style="text-transform:capitalize" onkeyup="javascript:this.value=this.value.charAt(0).toUpperCase() + this.value.substr(1);" />

<label for="email">eMail</label>
<input type="email" name="email" id="email" />

<label for="club">Address</label>
<input type="text" name="address" id="address" list="" style="text-transform:capitalize" onkeyup="javascript:this.value=this.value.charAt(0).toUpperCase() + this.value.substr(1);" />

<label for="club">City</label>
<input type="text" name="city" id="city" list="" style="text-transform:capitalize" onkeyup="javascript:this.value=this.value.charAt(0).toUpperCase() + this.value.substr(1);" />

<label for="club">State</label>
<input type="text" name="state" id="state" list="" style="text-transform:capitalize" onkeyup="javascript:this.value=this.value.charAt(0).toUpperCase() + this.value.substr(1);" />

<label for="club">Zip</label>
<input type="number" pattern="\d{5}" name="zip" id="zip" value="" required="true" placeholder="" />

<label for="phone">Phone</label>
<input type="text" name="phone" id="phone" value="" placeholder="" list="" pattern="[\(]\d{3}[\)]\s\d{3}[\-]\d{4}" title='Phone Number Format: (999) 999-9999' onkeydown="javascript:backspacerDOWN(this,event);" onkeyup="javascript:backspacerUP(this,event);" />

<label for="phone">Alt Phone</label>
<input type="text" name="altphone" id="altphone" value="" placeholder="" list="" pattern="[\(]\d{3}[\)]\s\d{3}[\-]\d{4}" title='Phone Number Format: (999) 999-9999' onkeydown="javascript:backspacerDOWN(this,event);" onkeyup="javascript:backspacerUP(this,event);" />

<label for="phone">Fax</label>
<input type="text" name="fax" id="fax" value="" placeholder="" list="" pattern="[\(]\d{3}[\)]\s\d{3}[\-]\d{4}" title='Phone Number Format: (999) 999-9999' onkeydown="javascript:backspacerDOWN(this,event);" onkeyup="javascript:backspacerUP(this,event);" />

<label for="club">Car Club</label>
<input type="text" name="club" id="club" list="" style="text-transform:capitalize" onkeyup="javascript:this.value=this.value.charAt(0).toUpperCase() + this.value.substr(1);" />

<label for="club">Access</label>
<input type="text" name="access" id="access" list="" style="text-transform:capitalize" onkeyup="javascript:this.value=this.value.charAt(0).toUpperCase() + this.value.substr(1);" />

<label for="year">Year</label>
<input type="number" pattern="\d{4}" name="year" id="year" value="" required="true" placeholder="" />

<label for="make">Make</label>
<input type="text" name="make" id="make" required="true" list="makes" style="text-transform:capitalize" onkeyup="javascript:this.value=this.value.charAt(0).toUpperCase() + this.value.substr(1);" />

<label for="model">Model</label>
<input type="text" name="model" id="model" required="true" list="models" style="text-transform:capitalize" onkeyup="javascript:this.value=this.value.charAt(0).toUpperCase() + this.value.substr(1);" />

<label for="plates">Plates</label>
<input type="text" name="plates" id="plates" list="" style="text-transform:uppercase" onkeyup="javascript:this.value=this.value.toUpperCase();" />

<fieldset>
<legend><h2>Registration Notes</h2></legend>
<textarea rows="5" cols="80%" name="regnotes" id="regnotes"></textarea>
</fieldset><br><br>
<input type="submit" name="reg-submit" id="reg-submit" value="Submit" />
</fieldset> <!-- Registration Form-->

<?php include("includes/datalist.php"); ?>

</form>


process.php

<?php
include("includes/connect.php");
error_reporting(E_ALL);
ini_set('display_errors', 'On');
date_default_timezone_set('US/Central');
session_start();

$datenow = date("y-m-d");
$timenow = date("h:i:sa");
$error = FALSE;

if (!isset($entrynum)) {
$error = TRUE;
}

if (isset($_POST['class'])) {
$class = $_POST['class'];
$class = trim($class);
$class = strip_tags($class);
}

// registration
if (!empty($_POST['reg-submit'])) {
$entrynum = $_POST['entrynum'];

$_SESSION['entrynum'] = $entrynum;

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$altphone = $_POST['altphone'];
$fax = $_POST['fax'];
$club = $_POST['club'];
$access = $_POST['access'];
$year = $_POST['year'];
$make = $_POST['make'];
$model = $_POST['model'];
$plates = $_POST['plates'];

$regnotes = $_POST['regnotes'];
if (isset($regnotes)) {
$regnotes = trim($regnotes);
$regnotes = strip_tags($regnotes);
}

$sql = "INSERT INTO HeatWaveData (`entrynum`, `fname`, `lname`, `email`, `address`, `city`, `state`, `zip`, `phone`, `altphone`, `fax`, `club`, `access`, `year`, `make`, `model`, `plates`, `regnotes`, `dated`, `timed`)
VALUES ('$entrynum', '$fname', '$lname', '$email', '$address', '$city', '$state', '$zip', '$phone', '$altphone', '$fax', '$club', '$access' '$year', '$make', '$model', '$plates', '$regnotes', '$datenow', '$timenow')
ON DUPLICATE KEY
UPDATE entrynum='$entrynum', fname='$fname', lname='$lname', email='$email', address='$address', city='$city', state='$state', zip='$zip', phone='$phone', altphone='$altphone', fax='$fax', club='$club', access='$access', year='$year', make='$make', model='$model', plates='$plates', regnotes='$regnotes', dated='$datenow', timed='$timenow'";

if (!$db->query($sql)) { die("Error: {$db->errno} : {$db->error}"); }

header("Refresh: 3; url=upload.php");
}
?>

Answer

You're missing a comma in your values line, between $access and $year

VALUES ('$entrynum', '$fname', '$lname', '$email', '$address', '$city',
  '$state', '$zip', '$phone', '$altphone', '$fax', '$club', '$access', <--
  '$year', '$make', '$model', '$plates', '$regnotes', '$datenow', '$timenow')
Comments