/    Sign up×
Community /Pin to ProfileBookmark

Column count doesn’t match value count at row 1 Error

Hi,

i am trying to store some values into a database, but upon trying to add i am getting a “Column count doesn’t match value count at row 1”

i believe i am passing something incorrectly but was hoping someone could point me in the right direction

i have included my code [URL=”<script src=”http://pastebin.com/embed_js.php?i=JTrXc23V”></script>”]here[/URL]

many thanks

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@holyhttpSep 07.2012 — You certainly do not have the correct number of field data in the first row of your query.

It maybe because you have a misplaced comma or quote somewhere.

If you need an extra pair of eyes then paste your query for us to see.

Please double check, and you'll discover you were missing something.
Copy linkTweet thisAlerts:
@nzzauthorSep 07.2012 — thanks for the reply

my code is here > http://pastebin.com/JTrXc23V
Copy linkTweet thisAlerts:
@holyhttpSep 07.2012 — You did not indicate how many fields your database table has. So there is no way to make the column count comparison just by looking at your code.

There is an excessive use of single quotes in your query that forces you to add escape slashes and makes your code hard to read.

You have a syntax error at time () . ('

How about for instance:

$sql="INSERT INTO $dblist VALUES(

'0',

'".$_POST['userid']."',

'".$_
POST['location']."',

'".$row['type']."',

'".time ()."',

'".time ()."',

'".$expire."',

'".$row['expire']."'

'0',

'0',

'".$_POST['hide']."',

'".$_
POST['featured']."',

'".$_POST['status']."'",

'1',

'".$_
POST['stock']."',

'".$_POST['vin']."',

'".$_
POST['model_year']."',

'".$_POST['make']."',

'".$_
POST['model']."',

'".$_POST['cond']."',

'".$_
POST['category']."',

'".$_POST['category2']."',

'".$_
POST['mileage']."',

'".$_POST['mileage_alt']."',

'".$_
POST['price']."',

'".$_POST['sale']."',

'".$_
POST['price_alt']."',

'".$_POST['exterior']."',

'".$_
POST['interior']."',

'".$_POST['doors']."',

'".$_
POST['fuel']."',

'".$_POST['drive']."',

'".$_
POST['engine']."',

'".$_POST['trans']."',

'".$_
POST['top_speed']."',

'".$_POST['horsepower']."',

'".$_
POST['torque']."',

'".$_POST['towing']."',

'".$_
POST['features']."',

'".$_POST['description']."',

'".$_
POST['tagline']."',

'".$_POST['link_url']."',

'".$_
POST['link_text']."',

'".$_POST['ebay_url']."')";

if (!(mysql_query($sql, $link))){ exit (mysql_error ()); }

You also need to use the addslashes() function to all submitted data to prevent SQL injection (e.g addslashes($_POST['engine']) )

By using the $sql variable is provide and comparing the number of fields with the column count of your table you should be able to easily spot the errors.

Always write your code with simplicity and readability in mind.
Copy linkTweet thisAlerts:
@nzzauthorSep 10.2012 — Thanks for replying

i have 49 fields in my database (listed below)

id

userid

location

user_type

added

updated

expire

user_expire

viewed

images

hide

featured

status

pending

stock

vin

model_year

make

model

cond

category

category2

mileage

mileage_alt

price

sale

price_alt

mot

mot_expire

reg_plate

reg_docs

owners

exterior

interior

doors

fuel

drive

engine

trans

top_speed

horsepower

torque

towing

features

description

tagline

link_url

link_text

ebay_url

i have since removed the incorrect syntax

so the code now reads

'' . time () . '',

unfortunately this gives me a blank white page

if i get this fixed i will then make a start at improving my code
×

Success!

Help @nzz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...