1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP error column issue

Discussion in 'PHP' started by ianhaney, May 5, 2013.

  1. #1
    Hi

    I get the following error after pressing submit on my auction type website

    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[​IMG] 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

    PHP:
    1. return "INSERT INTO " . $DBPrefix . "auctions VALUES (NULL, " .$user->user_data['id'] . ", '" .  
    2. $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'] . "',
    3. '" . $_SESSION['SELL_make'] . "', '" . $_SESSION['SELL_model'] . "', '" . $_SESSION['SELL_number_doors'] . "', '"
    4. . $_SESSION['SELL_colour'] . "', '" . $_SESSION['SELL_year'] . "', '" . $_SESSION['SELL_fuel_type'] . "', '"  
    5. . $_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 . ")";
    6. }
    Thank you in advance

    Kind regards

    Ian
    ianhaney, May 5, 2013 IP
  2. Moustafa.Elkady

    Moustafa.Elkady Member

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #2
    try to use organized orm system
    Moustafa.Elkady, May 5, 2013 IP
  3. nipun5perera

    nipun5perera Greenhorn

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    This is what you have to do ,

    PHP:
    1. return "INSERT INTO " . $DBPrefix . "auctions (columname1,columname2,columname3,...) VALUES (NULL, " .$user->user_data['id'] . ", '" .
    2. $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'] . "',
    3. '" . $_SESSION['SELL_make'] . "', '" . $_SESSION['SELL_model'] . "', '" . $_SESSION['SELL_number_doors'] . "', '"
    4. . $_SESSION['SELL_colour'] . "', '" . $_SESSION['SELL_year'] . "', '" . $_SESSION['SELL_fuel_type'] . "', '"
    5. . $_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 . ")";
    6. }
    7.  

    In above code you'll see that i added (columname1,columname2,columname3,...) ,replace columname1,columname2,columname3,... with the corresponding colum name in the database, this way you can map database table coulms to the values you're submitting to database.
    nipun5perera, May 6, 2013 IP
  4. deathshadow

    deathshadow Prominent Member

    Messages:
    5,980
    Likes Received:
    827
    Best Answers:
    144
    Trophy Points:
    395
    #4
    nipun5perera has it right -- you're blindly sending multiple values, but you aren't actually stating what fields to shove them into!

    The proper format for a insert is:

    INSERT INTO tablename (column1,column2,column3) VALUES (value1,value2,value3)

    You must have the SAME number of columns as values, that way there's someplace to PUT your values. You don't even have a list of columns to plug things into! All you have is data!

    ... and horiffically bad methodology as well since you're manually adding query parameters together like it's still 2006 -- lemme guess, still using the deprecated mysql_ functions they've been telling us for eight years to stop using, and FINALLY added A giant red warning box to in the manual?

    This REALLY looks like one of those situations you should be using prepared queries... especially if you're going to have a function that's just vomiting up session variables.
    deathshadow, May 7, 2013 IP