Thanks to you guys, i now understand much better this whole thing, but i now have a problem where, after submit, i get the mysql error, "Column count doesn't match value count at row 1"

my form code is

<?php
// MySQL connection variables
$host="server"; 
$username="Vetsform"; 
$password="saerverpassxduhsjdkasjdlcc"; 
$db_name="Vetsform"; 
$tbl_name="vetform1"; 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

//Save data from the HTTP POST values submitted from the PDF
extract($_REQUEST);

// Insert all the data from above into the table in the database
$sql="INSERT INTO $tbl_name(Vet_First , Vet_Middle,
Vet_Email,
Vet_AreaCode,
Vet_PhonePrefix,
Vet_PhoneSuffix,
Vet_StreetAddress,
Vet_City,
Vet_Zip,
State,
Army,
Navy,
Airforce,
Nursing,
Other,
DateEnlisted,
Datedischarged,
Emg_Name_first,
Emg_Name_mi,
Emg_Name_Last,
Emg_Email,
Emg_Phone_Area,
Emg_Phone_Prefix,
Emg_Phone_Suffix,
Emg_Address,
Emg_City,
Emg_Zip,
Emg_State)
VALUES
('$Vet_First',
'$Vet_Middle:',
'$Vet_Email',
'$Vet_AreaCode',
'$Vet_PhonePrefix',
'$Vet_PhoneSuffix',
'$Vet_StreetAddress',
'$Vet_City',
'$Vet_Zip',
'$State'
'$Army',
'$Navy',
'$Airforce',
'$Nursing',
'$Other',
'$DateEnlisted',
'$Datedischarged',
'$Emg_Name_first',
'$Emg_Name_mi',
'$Emg_Name_Last',
'$Emg_Email',
'$Emg_Phone_Area',
'$Emg_Phone_Prefix',
'$Emg_Phone_Suffix',
'$Emg_Address',
'$Emg_City',
'$Emg_Zip',
'$Emg_State')";
$result=mysql_query($sql) or die(mysql_error());
// If it worked, say so...
// This will change later on so it won't have the like to view all users, obviously...that's just for testing purposes
if($result){
echo "Successful";
}

else {
echo "ERROR";
}

mail( "Crzycm16@verizon.net","Validate","hi","From: Validate@shsforms.com");

// Close connection to the database
mysql_close();
?>

hopefully you guys can see it, cuz i cant/ im pretty new at this.

VALUES
('$Vet_First',
'$Vet_Middle:', <<< is $Vet_Middle and not $Vet_Middle:

:)

VALUES
('$Vet_First',
'$Vet_Middle:', <<< is $Vet_Middle and not $Vet_Middle:

:)

I fixed that? but i still get the same error.
?

:-(

Well, as the error says, the columns specified in the insert query doesn't match with the values you are passing. Make sure that you have all the columns(in your table) ! insert into table (col1,col2) values (val1) and insert into table (col1) values (val1,val2) both would generate same error.

Actually failure to include a field name in sql code to be executed will bring up "Column count doesn't match value count at row 1" error.

For example sql statement 'sql="INSERT INTO table_name (field_1, field_2,field_3,field_4)' will generate the error above if values do not match for example 'VALUES('one','two')";'

1st i spot a typo error '$Vet_Middle:' but you said you removed the colon but still the problem exist... I patiently recount your data and there is no problem you had 28 fields in your insert into values.... the last thing that's bugging me that may cause the problem would be storing incorrect data type on a specific field. i mean for ex. if you set the a field to data type int... the value should be inserted would be an integer. Try to review your data.

Hey I am having this same issue. I looked through a lot of forums but I cant seem to stop getting the error. I even changed all my fields to varchar() here is my code.

$con=mysql_connect($host, $username, $pass);
if(!$con)
{
    die("Could Not Connect: ".mysql_error());
}
mysql_select_db($db);


$CustLName=$_POST['CustLName'];
$CustFName=$_POST['CustFName'];
$CBR=$_POST['CBR'];
$AcctNum=$_POST['AcctNum'];
$CustCode=$_POST['CustCode'];
$SourceTN=$_POST['SourceTN'];
$SSID=$_POST['SSID'];
$AcctType=$_POST['AcctType'];
$AuthSys=$_POST['AuthSys'];
$CSRSentID=$_POST['CSRSentID'];
$EscSentID='ap608u';
$Issue=$_POST['Issue'];
$EscNum=date('U');
$Program=$_POST['Program'];
if(isset($_POST['Submit']))
{
    $addNew=mysql_query("INSERT INTO $mirtable ( ID, EscNum , EscSentID, CSRSentID, CustFName, CustLName, AcctNum, AcctType, CustCode, Issue, STN, AuthSys, SSID, CBR, Program) VALUES('', '$EscNum', '$EscSentID', '$CSRSentID', '$CustFName', '$CustLName', '$AcctNum,' '$AcctType', '$CustCode', '$Issue', '$SourceTN', '$AuthSys', '$SSID', '$CBR', '$Program')") or die ("Error in query: .\n\nQuery: $addNew\n\nError: " .mysql_error());
}
Member Avatar for diafol

Anybody wishing to answer HueyLouis's question should go to his NEW article here.
The last post to this thread was 2 years ago and prior to that 4 years ago. Unless your question is directly related to the original post, consider starting a new article?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.