PHP error column issue

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

ianhaney
New php-forum User
New php-forum User
Posts: 27
Joined: Tue May 01, 2012 12:30 pm

PHP error column issue

Postby ianhaney » Sun May 05, 2013 12:45 am

Hi

I added extra fields following the link below

http://www.webidsupp....ight=condition

I get the following error after pressing submit

An unexpected error occurred. The error has been forwarded to our technical team and will be fixed shortly

I checked the error log just now in admin ->tools and has the following

Ford Mondeo

', '', 198, 0, '299', '0', '0', '299', '1', '1',
'1', '2', 'Array', 'Silver', '3', '2', '1', '0', '2', '1', 0, '1367774117', 0, 0, 1, 1, 0, 0, 0, 0, 'n', '', 'y', 'n', 'n', 'n', 0.00)
Column count doesn't match value count at row 1
page:/home/sites/247autotrade.com/public_html/sell.php line:108

I found it is because I have a field short in the coding I am guessing as also found out there are more database columns than there are values, is that right? if so just unsure how to correct it

I have been trying to fix it for ages but can't seem to do it

Is it to do with the coding below

Code: Select all

return "INSERT INTO " . $DBPrefix . "auctions VALUES (NULL, " .$user->user_data['id'] . ", '" .   
$system->cleanvars($_SESSION['SELL_title']) . "', '" . $system->cleanvars($_SESSION['SELL_subtitle']) . "', '" . $a_starts . "', '" . addslashes($_SESSION['SELL_description']) . "', '" . $system->cleanvars($_SESSION['SELL_pict_url']) . "', " . $_SESSION['SELL_sellcat1'] . ", " . intval($_SESSION['SELL_sellcat2']) . ", '" . $system->input_money(($_SESSION['SELL_buy_now_only'] == 'n') ? $_SESSION['SELL_minimum_bid'] : $_SESSION['SELL_buy_now_price']) . "', '" . $system->input_money($_SESSION['SELL_shipping_cost']) . "', '" . $system->input_money(($_SESSION['SELL_with_reserve'] == 'yes') ? $_SESSION['SELL_reserve_price'] : 0) . "', '" . $system->input_money(($_SESSION['SELL_with_buy_now'] == 'yes') ? $_SESSION['SELL_buy_now_price'] : 0) . "', '" . $_SESSION['SELL_atype'] . "', '" . $_SESSION['SELL_condition'] . "',   
'" . $_SESSION['SELL_make'] . "', '" . $_SESSION['SELL_model'] . "', '" . $_SESSION['SELL_number_doors'] . "', '"   
. $_SESSION['SELL_colour'] . "', '" . $_SESSION['SELL_year'] . "', '" . $_SESSION['SELL_fuel_type'] . "', '"   
. $_SESSION['SELL_duration'] . "', '" . $system->input_money($_SESSION['SELL_customincrement']) . "', '" . $_SESSION['SELL_shipping'] . "', '" . $payment_text . "', " . (($_SESSION['SELL_international']) ? 1 : 0) . ", '" . $a_ends . "', 0, 0, " . (($_SESSION['SELL_file_uploaded']) ? 1 : 0) . ", " . $_SESSION['SELL_iquantity'] . ", 0, " . intval($_SESSION['SELL_relist']) . ", 0, 0, 'n', '" . $system->cleanvars($_SESSION['SELL_shipping_terms']) . "', '" . $_SESSION['SELL_buy_now_only'] . "', '" . $_SESSION['SELL_is_bold'] . "', '" . $_SESSION['SELL_is_highlighted'] . "', '" . $_SESSION['SELL_is_featured'] . "', " . $fee . ")";   
}


Thank you in advance

Kind regards

Ian

User avatar
sandeep605085
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions
Contact:

Re: PHP error column issue

Postby sandeep605085 » Sun May 05, 2013 10:47 am

Its better to put the column name along with values to track the errors.
and also if you put column name with values then if in future there is a need to add one more column in that database table, then the existing query will not get affected.

EXAMPLE:
qry1 = INSERT INTO table_name ('column1','column2','column3','column4')
VALUES
('value1','value2','value3','value4');

qry2 = INSERT INTO table_name VALUES ('value1','value2','value3','value4');

So by using qry1 method of writing query will help you to identify the missing values.
and if say one more column as column5 added to table_name then the qry1 will work with out error, where as qry2 will give error as Column count doesn't match value count.

Thanks,
Sandeep Agrawal
Mindfire Solutions.

ianhaney
New php-forum User
New php-forum User
Posts: 27
Joined: Tue May 01, 2012 12:30 pm

Re: PHP error column issue

Postby ianhaney » Sun May 05, 2013 12:51 pm

Hmm not sure how I would convert the following to the way you said

Code: Select all

return "INSERT INTO " . $DBPrefix . "auctions VALUES (NULL, " .$user->user_data['id'] . ", '" .   
$system->cleanvars($_SESSION['SELL_title']) . "', '" . $system->cleanvars($_SESSION['SELL_subtitle']) . "', '" . $a_starts . "', '" . addslashes($_SESSION['SELL_description']) . "', '" . $system->cleanvars($_SESSION['SELL_pict_url']) . "', " . $_SESSION['SELL_sellcat1'] . ", " . intval($_SESSION['SELL_sellcat2']) . ", '" . $system->input_money(($_SESSION['SELL_buy_now_only'] == 'n') ? $_SESSION['SELL_minimum_bid'] : $_SESSION['SELL_buy_now_price']) . "', '" . $system->input_money($_SESSION['SELL_shipping_cost']) . "', '" . $system->input_money(($_SESSION['SELL_with_reserve'] == 'yes') ? $_SESSION['SELL_reserve_price'] : 0) . "', '" . $system->input_money(($_SESSION['SELL_with_buy_now'] == 'yes') ? $_SESSION['SELL_buy_now_price'] : 0) . "', '" . $_SESSION['SELL_atype'] . "', '" . $_SESSION['SELL_condition'] . "',   
'" . $_SESSION['SELL_make'] . "', '" . $_SESSION['SELL_model'] . "', '" . $_SESSION['SELL_number_doors'] . "', '"   
. $_SESSION['SELL_colour'] . "', '" . $_SESSION['SELL_year'] . "', '" . $_SESSION['SELL_fuel_type'] . "', '"   
. $_SESSION['SELL_duration'] . "', '" . $system->input_money($_SESSION['SELL_customincrement']) . "', '" . $_SESSION['SELL_shipping'] . "', '" . $payment_text . "', " . (($_SESSION['SELL_international']) ? 1 : 0) . ", '" . $a_ends . "', 0, 0, " . (($_SESSION['SELL_file_uploaded']) ? 1 : 0) . ", " . $_SESSION['SELL_iquantity'] . ", 0, " . intval($_SESSION['SELL_relist']) . ", 0, 0, 'n', '" . $system->cleanvars($_SESSION['SELL_shipping_terms']) . "', '" . $_SESSION['SELL_buy_now_only'] . "', '" . $_SESSION['SELL_is_bold'] . "', '" . $_SESSION['SELL_is_highlighted'] . "', '" . $_SESSION['SELL_is_featured'] . "', " . $fee . ")";   
}

User avatar
sandeep605085
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions
Contact:

Re: PHP error column issue

Postby sandeep605085 » Sun May 05, 2013 9:54 pm

return "INSERT INTO " . $DBPrefix . "auctions VALUES (NULL, " .$user->user_data['id'] . ", '" .
$system->cleanvars($_SESSION['SELL_title']) . "', ...............);


in above query
NULL refers to first column for the table DBPrefix.
$user->user_data['id'] refers to second column of the table DBPrefix.
$system->cleanvars($_SESSION['SELL_title']) refers to the third column of the table DBPrefix.
and so on.

so in this way you can identify the column names to the respective value.

Thanks,
Sandeep Agrawal
Mindfire Solutions.

ianhaney
New php-forum User
New php-forum User
Posts: 27
Joined: Tue May 01, 2012 12:30 pm

Re: PHP error column issue

Postby ianhaney » Sun May 05, 2013 10:39 pm

Hi sandeep605085

If that is the case, id is the first column table so it seems to be missing that one, that right?

I attached a url link of the order of the columns below

[url]
www.247autotrade.com/sqlthree.png
[/url]

User avatar
sandeep605085
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions
Contact:

Re: PHP error column issue

Postby sandeep605085 » Mon May 06, 2013 3:57 am

I am unable to access
http://www.247autotrade.com/sqlthree.png

can you please check.

Thanks,
Sandeep Agrawal
Mindfire Solutions

ianhaney
New php-forum User
New php-forum User
Posts: 27
Joined: Tue May 01, 2012 12:30 pm

Re: PHP error column issue

Postby ianhaney » Mon May 06, 2013 4:26 am

Try now, should be able to see it now

User avatar
sandeep605085
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions
Contact:

Re: PHP error column issue

Postby sandeep605085 » Mon May 06, 2013 9:16 am

By looking at screen shot it looks like only 24 column is present in that table but your sql query is inserting 42 record in that table.

Looking at the column name and PHP variable in your sql query i am able to identify the column name with respective value.

in below comparison of column name and value
the first value NULL should not be there,
after shipping there should be more column to match the values.

-----------------------------------------------------------
return "INSERT INTO " . $DBPrefix . "auctions VALUES (
NULL,
id = " .$user->user_data['id'] . ",
title = '" . $system->cleanvars($_SESSION['SELL_title']) . "',
subtitle = '" . $system->cleanvars($_SESSION['SELL_subtitle']) . "',
starts = '" . $a_starts . "',
description = '" . addslashes($_SESSION['SELL_description']) . "',
pict_url = '" . $system->cleanvars($_SESSION['SELL_pict_url']) . "',
category = " . $_SESSION['SELL_sellcat1'] . ",
secondcat = " . intval($_SESSION['SELL_sellcat2']) . ",
minimum_bid = '" . $system->input_money(($_SESSION['SELL_buy_now_only'] == 'n') ? $_SESSION['SELL_minimum_bid'] : $_SESSION['SELL_buy_now_price']) . "',
shipping_cost = '" . $system->input_money($_SESSION['SELL_shipping_cost']) . "',
reserve_price = '" . $system->input_money(($_SESSION['SELL_with_reserve'] == 'yes') ? $_SESSION['SELL_reserve_price'] : 0) . "',
buy_now = '" . $system->input_money(($_SESSION['SELL_with_buy_now'] == 'yes') ? $_SESSION['SELL_buy_now_price'] : 0) . "',
auction_type = '" . $_SESSION['SELL_atype'] . "',
item_condition = '" . $_SESSION['SELL_condition'] . "',
make = '" . $_SESSION['SELL_make'] . "',
model = '" . $_SESSION['SELL_model'] . "',
number_doors = '" . $_SESSION['SELL_number_doors'] . "', '"
colour = . $_SESSION['SELL_colour'] . "',
year = '" . $_SESSION['SELL_year'] . "',
fuel_type = '" . $_SESSION['SELL_fuel_type'] . "', '"
duration = . $_SESSION['SELL_duration'] . "',
increment = '" . $system->input_money($_SESSION['SELL_customincrement']) . "',
shipping = '" . $_SESSION['SELL_shipping'] . "',
'" . $payment_text . "',
" . (($_SESSION['SELL_international']) ? 1 : 0) . ",
'" . $a_ends . "',
0,
0,
" . (($_SESSION['SELL_file_uploaded']) ? 1 : 0) . ",
" . $_SESSION['SELL_iquantity'] . ",
0,
" . intval($_SESSION['SELL_relist']) . ",
0,
0,
'n',
'" . $system->cleanvars($_SESSION['SELL_shipping_terms']) . "',
'" . $_SESSION['SELL_buy_now_only'] . "',
'" . $_SESSION['SELL_is_bold'] . "',
'" . $_SESSION['SELL_is_highlighted'] . "',
'" . $_SESSION['SELL_is_featured'] . "',
" . $fee . ")";
-----------------------------------------------------------


So your final query should be similar to below query but make sure below that below query is not correct
because of the missing field name after "shipping" fields and the value NULL at the beginning.

-----------------------------------------------------------
return "INSERT INTO " . $DBPrefix . "auctions (`id`, `title`, `subtitle`, `starts`, `description`, `pict_url`, `category`, `secondcat`,
`minimum_bid`,`shipping_cost`, `reserve_price`, `buy_now`, `auction_type`, `item_condition`, `make`,`model`, `number_doors`, `colour`, `year`,
`fuel_type`, `duration`, `increment`, `shipping`, more column needs to be here)
VALUES
(NULL, " .$user->user_data['id'] . ", '" . $system->cleanvars($_SESSION['SELL_title']) . "', '" . $system->cleanvars($_SESSION['SELL_subtitle']) . "', '" . $a_starts . "', '" . addslashes($_SESSION['SELL_description']) . "', '" . $system->cleanvars($_SESSION['SELL_pict_url']) . "'," . $_SESSION['SELL_sellcat1'] . ", " . intval($_SESSION['SELL_sellcat2']) . ",'" . $system->input_money(($_SESSION['SELL_buy_now_only'] == 'n') ? $_SESSION['SELL_minimum_bid'] : $_SESSION['SELL_buy_now_price']) . "', '" . $system->input_money($_SESSION['SELL_shipping_cost']) . "', '" . $system->input_money(($_SESSION['SELL_with_reserve'] == 'yes') ? $_SESSION['SELL_reserve_price'] : 0) . "','" . $system->input_money(($_SESSION['SELL_with_buy_now'] == 'yes') ? $_SESSION['SELL_buy_now_price'] : 0) . "','" . $_SESSION['SELL_atype'] . "', '" . $_SESSION['SELL_condition'] . "', '" . $_SESSION['SELL_make'] . "','" . $_SESSION['SELL_model'] . "','" . $_SESSION['SELL_number_doors'] . "','" . $_SESSION['SELL_colour'] . "','" . $_SESSION['SELL_year'] . "','" . $_SESSION['SELL_fuel_type'] . "', '" . $_SESSION['SELL_duration'] . "','" . $system->input_money($_SESSION['SELL_customincrement']) . "','" . $_SESSION['SELL_shipping'] . "','" . $payment_text . "', " . (($_SESSION['SELL_international']) ? 1 : 0) . ",'" . $a_ends . "',0,0, " . (($_SESSION['SELL_file_uploaded']) ? 1 : 0) . "," . $_SESSION['SELL_iquantity'] . ",0, " . intval($_SESSION['SELL_relist']) . ", 0,0,'n','" . $system->cleanvars($_SESSION['SELL_shipping_terms']) . "','" . $_SESSION['SELL_buy_now_only'] . "','" . $_SESSION['SELL_is_bold'] . "','" . $_SESSION['SELL_is_highlighted'] . "','" . $_SESSION['SELL_is_featured'] . "', " . $fee . ")";
-----------------------------------------------------------

Thanks,
Sandeep Agrawal
Mindfire Solutions.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 3 guests

cron