majocmatt Posted April 7, 2006 Share Posted April 7, 2006 [code]// On the previous page, if you select USA, you pick multiple states.// For some reason, my loop isn't inserting multiple entries into the DB// If I run print statements within the loop, everything prints to the screen // correctly... But it only inserts the first one in the array of #states// Any idea why?// $repid is the user id, insignificant to the problem, asssume its 1 // get values from country and states$countries = $_POST['countries']; // array$states = $_POST['state']; // array // get amount of each entity$number_of_countries = count($_POST['countries']);$number_of_states = count($_POST['state']); $number_of_provinces = count($_POST['province']); $number_of_territories = count($_POST['territory']); // loop thru countries then states and insert into db accordinglyfor($c = 0; $c < $number_of_countries; $c++) { if($countries[$c] == "100") { // 100 == USA // state id entry for($s = 0; $s < $number_of_states; $s++) { mysql_query("INSERT INTO reps_coverage VALUES ('".$countries[$c]."','$repid','".$states[$s]."')"); } }} [/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 7, 2006 Share Posted April 7, 2006 And your question is?When ever you post any code, explain what you want it to do and tell us what it is doing wrong. Don't just post code and expect the correct answer to appear.Ken 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.