Colton.Wagner Posted October 16, 2009 Share Posted October 16, 2009 I am tryin to loop the same number into a databas 17659 times but with the following code: <?php error_reporting(E_ALL); $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Connection Error:' . mysql_error()); } mysql_select_db('catgories', $con); for($i=0;$i<=17659;$i++) { $query="INSERT INTO categories(`products_id`,`categories_id`) select $i,categories_id from categories"; mysql_query($query) or trigger_error("SQL: $query, ERROR: ", E_USER_ERROR); } ?> However I get the following error: Fatal error: SQL: INSERT INTO categories ('products_id'. 'categories_id') VALUES ('', '18'), ERROR: in H:\Xampp\xampplite\htdocs\categories.php on line 13 Quote Link to comment Share on other sites More sharing options...
cags Posted October 16, 2009 Share Posted October 16, 2009 This is the second thread you've started on this problem. The trigger error has . mysql_error() missing from it (as I forgot to include it originally in your last thread) so we can't actually see why the query failed. But as was mentioned in the last thread, theres a good change it doesn't like the '' for an auto increment field nor the single quotes around an integer value. Not to mention the fact that the error message your showing us is nothing todo with that code, since the last line is set to echo out $query, and the string in your error message doesn't match the value of $query. Quote Link to comment Share on other sites More sharing options...
AviNahum Posted October 16, 2009 Share Posted October 16, 2009 <?php error_reporting(E_ALL); $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Connection Error:' . mysql_error()); } mysql_select_db('catgories', $con); for($i=0;$i<=17659;$i++) { $query="INSERT INTO categories(products_id, categories_id) select $i,categories_id from categories"; mysql_query($query) or trigger_error("SQL: $query, ERROR: ", E_USER_ERROR); } ?> Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 16, 2009 Share Posted October 16, 2009 this would be an SQL issue, not PHP since your loop is fine .. it's just your query. well, your isn't 100% if you want to loop 17659 and not 17660 .. change $i=0 to $i=1 .. this way, you will loop through from 1-17659, and not from 0-17659; 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.