Jump to content

[SOLVED] Trying to insert 15 queries into mysql at once, but only 10 will go.


blurredvision

Recommended Posts

I have 15 separate INSERT INTO queries that I'm trying to insert into a table with one mysqli_multi_query function.  However, only the first 10 of the 15 are going.  I even attempted sending up the first 10, closing the connection, then reopening and sending the next 5, but that's not working either, just the first 10 show up.

 

Before I post any code, I wanted to see if there was some kind ceiling I was hitting.  Everything from the query statements (#'s 11 through 15 were copied and pasted from #'s 1 through 10 that work fine) to my columns in the table (there's enough room for the data I'm sending) look good.

 

So, can you guys give me a quick hint as to what's going on, or will I have to post the code?

Link to comment
Share on other sites

My guess would be you are duplicating index values and receiving an error from the query but your code has no error checking, error reporting, or error recovery logic in it to get it to tell you why it is failing.

 

Without showing us what you are doing (code and data), no one can directly help you.

Link to comment
Share on other sites

I have attached the basis of my queries to insert them into the database.  When I run it like this, the data for the first 10 weeks insert perfectly fine.  I have absolutely no issues with the first 10.  However, the remaining 5 do not show up.  I currently only have error checking on the database connection, but I don't know how to error check the queries.  Also, in my PHP error checking, nothing shows as wrong.

 

		$week1insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',1,'{$_POST['week1']}','{$_POST['week1_home']}')";
	$week2insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',2,'{$_POST['week2']}','{$_POST['week2_home']}')";
	$week3insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',3,'{$_POST['week3']}','{$_POST['week3_home']}')";
	$week4insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',4,'{$_POST['week4']}','{$_POST['week4_home']}')";
	$week5insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',5,'{$_POST['week5']}','{$_POST['week5_home']}')";
	$week6insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',6,'{$_POST['week6']}','{$_POST['week6_home']}')";
	$week7insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',7,'{$_POST['week7']}','{$_POST['week7_home']}')";
	$week8insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',8,'{$_POST['week8']}','{$_POST['week8_home']}')";
	$week9insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',9,'{$_POST['week9']}','{$_POST['week9_home']}')";
	$week10insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',10,'{$_POST['week10']}','{$_POST['week10_home']}')";
	$week11insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',11,'{$_POST['week11']}','{$_POST['week11_home']}')";
	$week12insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',12,'{$_POST['week12']}','{$_POST['week12_home']}')";
	$week13insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',13,'{$_POST['week13']}','{$_POST['week13_home']}')";
	$week14insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',14,'{$_POST['week14']}','{$_POST['week14_home']}')";
	$week15insert = "INSERT INTO schedules (gamertag_id,season,week,opponent,home_away) VALUES ('$gamertag','$season',15,'{$_POST['week15']}','{$_POST['week15_home']}')";

	mysqli_multi_query($dbc, "$week1insert;$week2insert;$week3insert;$week4insert;$week5insert;$week6insert;$week7insert;$week8insert;$week9insert;$week10insert;$week11insert,$week12insert;$week13insert;$week14insert;$week15insert");

Link to comment
Share on other sites

I recommend forming the query in a variable and then echoing it to see what it actually contains.

 

It would also be easier to use the multi-row insert syntax -

 

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

 

I think you and Ronnie were right.  I changed my 15 different variables to just one multi-row insert syntax, and voila, now it works fine, and all 15 rows now show as expected.  Must have been a 10-insert limit somewhere for my server.

 

Thanks a lot guys!

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.