phoenixx Posted August 26, 2008 Share Posted August 26, 2008 Everything was working fine after inserting thousands of entries. I'm actually scraping data from an external site. I tried commenting out the one line of code I thought might be giving it an issue but keeps coming back to the error being in the following code (sql insertion). //Writes the information to the database $sql = sprintf ("INSERT INTO cl_prods(clprods_id, clprods_manufacturer, clprods_category, clprods_sku, clprods_includes, clprods_collection, clprods_group, clprods_type, clprods_style, clprods_description, clprods_keywords, clprods_details, clprods_imglarge, clprods_imgmedium, clprods_imgsmall, clprods_imgthumb, clprods_cost, clprods_pricecl, clprods_price40, clprods_price50, clprods_status, clprods_timestamp, clprods_collected) VALUES ('','$mnfctr','$cat','$skunum','$including','$collectionname','$groupname','$typename','$stylename','$description1','$keywords1','$description2','$k5','$k6','$k99','$k98','$k97','$k96','$k95','$k94','$status','$timestamp','$k')") or die(mysql_error()); mysql_query ($sql); Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 26, 2008 Share Posted August 26, 2008 And why do you use sprintf here? Quote Link to comment Share on other sites More sharing options...
phoenixx Posted August 26, 2008 Author Share Posted August 26, 2008 I'm using mysql_real_escape_string in string arrays to get rid of the issues with quotes Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 26, 2008 Share Posted August 26, 2008 Just try $sql = "INSERT INTO cl_prods(clprods_id, clprods_manufacturer, clprods_category, clprods_sku, clprods_includes, clprods_collection, clprods_group, clprods_type, clprods_style, clprods_description, clprods_keywords, clprods_details, clprods_imglarge, clprods_imgmedium, clprods_imgsmall, clprods_imgthumb, clprods_cost, clprods_pricecl, clprods_price40, clprods_price50, clprods_status, clprods_timestamp, clprods_collected) VALUES ('','$mnfctr','$cat','$skunum','$including','$collectionname','$groupname','$typename','$stylename','$description1','$keywords1','$description2','$k5','$k6','$k99','$k98','$k97','$k96','$k95','$k94','$status','$timestamp','$k')"; And one more thing, use: or die(mysql_error()); in mysql_query() line Quote Link to comment Share on other sites More sharing options...
phoenixx Posted August 26, 2008 Author Share Posted August 26, 2008 Working great after removing sprintf. Out of curiosity what would have made the error caused by the sprintf? Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 26, 2008 Share Posted August 26, 2008 This function needs at least two arguments and was totally useless in your case. Read more at: http://www.php.net/manual/en/function.sprintf.php Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 This function needs at least two arguments and was totally useless in your case. Read more at: http://www.php.net/manual/en/function.sprintf.php No it doesn't. You only use as many parameters as you have substitutes for. Have you ever programmed in C and used printf()? Quote Link to comment Share on other sites More sharing options...
phoenixx Posted August 26, 2008 Author Share Posted August 26, 2008 Many thanks! The PHPFreaks community comes through again. Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 26, 2008 Share Posted August 26, 2008 No it doesn't. You only use as many parameters as you have substitutes for. Have you ever programmed in C and used printf()? Ok...It actually needs only one argument and throws no warning if there's only one. On the other hand it's pointless to call it with one argument only. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 No it doesn't. You only use as many parameters as you have substitutes for. Have you ever programmed in C and used printf()? Ok...It actually needs only one argument and throws no warning if there's only one. On the other hand it's pointless to call it with one argument only. No, what if he wants to use it's capabilities down the line? Less typing later. =/ Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 26, 2008 Share Posted August 26, 2008 I don't think I get you... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 I don't think I get you... If later, he wants to change the query and feels like using sprintf() to its fullest extent, he can with less change to the code. It really doesn't matter. Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 26, 2008 Share Posted August 26, 2008 I get you now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.