Title

Tuesday, 20 January 2015

PHP - Column count doesn't match value count.


hello this my code.

print_r($_POST);  foreach ($_POST as $key => $value){   echo $$key = $value;  }    echo $dpopName1= json_encode($_POST['dpopName']);  echo $dpopPosition1= json_encode($_POST['dpopPosition']);  echo $dpopLocation1= json_encode($_POST['dpopLocation']);     if($sub_cat=='all') {   $sub_cat='';   }    //$sql = mysql_query("INSERT INTO venders(vender_name, contact_personName,category, subcategory,email,contact_no,address,city,state,pin_code) VALUES ('$vendor_name', '$cont_personName','$cat_type','$sub_cat','$vendor_email', '$contact_no','$vendor_address','$state','$city','$vendor_pin')") or die(mysql_error());   $insertQuery=mysql_query("INSERT IGNORE INTO `venders`(`vender_name`, `vendor_ddNo`, `vendor_ddDate`,   `vendor_regid`, `dateCorp`, `contact_personName`, `category`, `subcategory`, `email`, `contact_no`, `fax_no`,   `website`, `address`, `city`, `taluka`, `state`, `pin_code`, `vendor_Baddress`, `Bstate`, `Bcity`, `Bvendor_pin`,   `Btaluka`, `Bcontact_no`, `Bfax_no`, `Bvendor_email`, `Bwebsite`, `govtUndertake`, `stateUndertake`, `publiclCompany`,   `privatelCompany`, `copSociaty`, `partnerFirm`, `propritorship`, `anyOtherspecify`, `dpopName`, `dpopPosition`,   `dpopLocation`, `panDetails`, `panRequireFor`, `serviceTaxregDetails`, `serviceTaxrequiredFor`, `pfRegisterDetails`,   `pfRequireFor`, `excDutyreg`, `excRequireFor`, `labourLicensedetails`, `licencePanrequireFor`, `stvRegNo`,   `stvRequireFor`, `stvregDateDetails`, `stvregDateRequiredFor`, `orgStrngth`, `NameofCompany`, `NameofBank`,   `nameOfbankBranch`, `cityofMB`, `accountNo`, `accountType`, `bankBranchIfsccode`, `micrCodeofBankbranch`,   `otherBankerDetails`) VALUES ('$vendor_name','$vendor_ddNo','$vendor_ddDate','$vendor_id','$dateCorp','$cont_personName','$vendor_address',   '$cat_type','$sub_cat','$vendor_email','$contact_no','$fax_no','$website','$vendor_address','$city','$taluka','$state','$vendor_pin',   '$vendor_Baddress','$Bstate','$Bcity','$Bvendor_pin','$Btaluka','$Bcontact_no','$Bfax_no','$Bvendor_email','$Bwebsite','$govtUndertake',   '$stateUndertake', '$publiclCompany',   '$privatelCompany', '$copSociaty', '$partnerFirm', '$propritorship', '$anyOtherspecify', '$dpopName1', '$dpopPosition1',   '$dpopLocation1','$panDetails', '$panRequireFor', '$serviceTaxregDetails', '$serviceTaxrequiredFor', '$pfRegisterDetails',   '$pfRequireFor', '$excDutyreg', '$excRequireFor', '$labourLicensedetails', '$licencePanrequireFor', '$stvRegNo',   '$stvRequireFor', '$stvregDateDetails', '$stvregDateRequiredFor', '$orgStrngth', '$NameofCompany', '$NameofBank',   '$nameOfbankBranch', '$cityofMB', '$accountNo', '$accountType', '$bankBranchIfsccode', '$micrCodeofBankbranch',   '$otherBankerDetails')") or die(mysql_error());   ?>
  1. Array to string conversion error 2.Column count doesn't match value count at row 1.

i tried following to solve the prooblem. 1. for solving 1st error i use json encode to convert the array into json string then i place the json string variable into insert table. 2. for column count error i checked wheather my database id has a primary key or not and it has a primary key then also i count all the value and column and also i cross check all the syntax but i found nothing. so guys please help me to solve the prooblem thank you.

Answer

A better way... to insert, when you're inserting alot of columns is... to use INSERT INTO SET, because then you have a better idea of which columns are missing.. than meticulously going through your mapped INSERT, and checking whether you have every column to every value.

INSERT INTO sometable   SET field1 = 'value1',   field2 = 'value2',   field3 = 'value3'

(Milov, 2004).

It also helps, to escape every single value that you are inserting.

Answer2

Of any of your variables contains a ' that would destroy your query.

You should put your query in $query before and add

or {   echo $query;   die...

At the end

Answer3

I notice this small mistake: You use

`

instead of

'

which is totally wrong.

No comments:

Post a Comment