SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,877
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)

    MySql insert question

    Hey guys

    I have an insert statement like this:

    insert into table_name (colm1, colm2, colm3, colm5) VALUES ('','','','');

    But it gives me the following error:

    Column count doesn't match value count at row 1

    After googling around a bit, It seems that I must include all columns from the table in the insert. Is that correct? So I cannot omit colm4, even if it is going to be null?

    Thanks for any feedback

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, you can omit columns. If that was the real query it would work fine. I bet it's some minor syntax error you're overlooking, a typo.

    Share the real query and you can get a fresh set of eyes on it.

  3. #3
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,877
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    ah ok. That would be fantastic. As fresh eyes might see something I do not.

    here is the query:
    Code PHP:
    $qry = "INSERT INTO `TableName` (`business_name`, `contact`, `tel_num`, `fax_num`,`email`, `cell_num`, `address`, ";
    $qry .= "`postal_address`, `business_mobile`, `business_email`, `business_fax`, `URL`, `accounts_contact`, `accounts_email`, ";
    $qry .= "`short_name`, `credit`, `vat_num`, `supplier_type_id`) VALUES ('$TradingName', '$contact', "; 
    $qry .= "'$Tell', '$Fax', '$Email', '$Cell', '$address', ";
    $qry .= "'$post_address', '$BusCell', '$BusEmail', '$BusFax', '$BusUrl', ";
    $qry .= "'$contactDetails', '$ContactEmail', '$FinName', '$FinTurnover', '$VAT', ";
    $qry .= "$rdoCompany)";

    Thanks for the help

  4. #4
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Possibly wrong, but the last value given is
    $qry .= "$rdoCompany)";

    should it be
    $qry .= " '$rdoCompany' )";
    ?

  5. #5
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,877
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    I can try that, but thought it is not needed as it is of type int. Will give it a shot tho and let you guys know. But I am thinking its a comma or something missing somewhere as to way its complaining about columns, etc

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That query is fine. I created that table and ran it, no error.

    Which means that one or more of those variables contains a value with unescaped single quotes. You need to call mysql_real_escape_string on each of those values before putting them in the query.

  7. #7
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,877
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    ah ok. Thanks a lot for the help. I will do that. Could be that one variable is like this:

    $eg = "$val1, $val2, $val3";

    So I will just split that with $val1.','.$val2 etc

    Thanks again

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't see how changing the way you concatenate strings will help?

  9. #9
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,877
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    Just to make sure I have all my bases covered.

  10. #10
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    <~ Honestly confused.

    How can changing the way you concatenate strings help or hurt anything?

  11. #11
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,877
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    lol. I dnt no. I was thinking maybe the commas is being read as 3 values instead of just one. Just an idea. I do not know PHP that well.

  12. #12
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,877
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    Thanks again for the help. The problem was exactly as you said. I found the rouge ' and eradicated it. lol.

    Thanks all for the help

  13. #13
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •