Jump to content

error: Looping an Insert Into mysql


Colton.Wagner

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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);
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.