OldWest Posted November 22, 2010 Share Posted November 22, 2010 I cannot get this INSERT to work. Not records are being added to the sys_city_dev table. No query errors are being thrown. I am simply trying to add ALL records from all_illinois to sys_city_dev and Mid should have be add as 11 in all inserts. city_name of course will be field city_name from all_illinois. Here is my code: $query = "SELECT * FROM all_illinois"; if ($results = mysqli_query($cxn, $query)) { $row_cnt = mysqli_num_rows($results); echo $row_cnt . " Total Records in Query.<br /><br />"; if (mysqli_num_rows($results)) { while ($rows = mysqli_fetch_array($results)) { echo $rows['city_name'] . "<br />"; $mid_id = '11'; $insert_city_query = "INSERT INTO sys_city_dev (ID, Mid, cityName, forder, disdplay, cid) VALUES (' ','" . $mid_id . "','" . $rows['city_name'] . "', '', '','')"; if (!$insert_city_query) exit(mysql_error()); } } } Here is my insert table structure and 5 records dump: -- -- Table structure for table `sys_city_dev` -- CREATE TABLE IF NOT EXISTS `sys_city_dev` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev` -- INSERT INTO `sys_city_dev` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'Dothan', 0, 0, 0), (84011, 1, 'Alabaster', 0, 0, 0), (84012, 1, 'Birmingham', 0, 0, 0), (84013, 2, 'Flagstaff', 0, 0, 0), (84014, 1, 'Auburn', 0, 0, 0); And the all_illinois dump w/ 5 records: -- -- Table structure for table `all_illinois` -- CREATE TABLE IF NOT EXISTS `all_illinois` ( `state_id` varchar(255) NOT NULL, `city_name` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `all_illinois` -- INSERT INTO `all_illinois` (`state_id`, `city_name`) VALUES ('135', 'Abingdon'), ('135', 'Adair'), ('135', 'Addieville'), ('135', 'Addison'), ('135', 'Adrian'); Quote Link to comment https://forums.phpfreaks.com/topic/219502-while-looped-insert-is-not-working-as-expected-no-errors/ Share on other sites More sharing options...
mikosiko Posted November 22, 2010 Share Posted November 22, 2010 $insert_city_query = "INSERT INTO sys_city_dev (ID, Mid, cityName, forder, disdplay, cid) VALUES (' ','" . $mid_id . "','" . $rows['city_name'] . "', '', '','')"; if (!$insert_city_query) exit(mysql_error()); } I don't see how record will be inserted.... mysql_query($insert_city_query) is not there Quote Link to comment https://forums.phpfreaks.com/topic/219502-while-looped-insert-is-not-working-as-expected-no-errors/#findComment-1138084 Share on other sites More sharing options...
OldWest Posted November 22, 2010 Author Share Posted November 22, 2010 $insert_city_query = "INSERT INTO sys_city_dev (ID, Mid, cityName, forder, disdplay, cid) VALUES (' ','" . $mid_id . "','" . $rows['city_name'] . "', '', '','')"; if (!$insert_city_query) exit(mysql_error()); } I don't see how record will be inserted.... mysql_query($insert_city_query) is not there Oh boy.. I haven't even started drinking egg nog yet and I do this? SOLVED! Quote Link to comment https://forums.phpfreaks.com/topic/219502-while-looped-insert-is-not-working-as-expected-no-errors/#findComment-1138085 Share on other sites More sharing options...
Muddy_Funster Posted November 22, 2010 Share Posted November 22, 2010 You're not seriously including the auto inc field in your insert statement are you?...'cause that would just be silly... Quote Link to comment https://forums.phpfreaks.com/topic/219502-while-looped-insert-is-not-working-as-expected-no-errors/#findComment-1138093 Share on other sites More sharing options...
OldWest Posted November 22, 2010 Author Share Posted November 22, 2010 You're not seriously including the auto inc field in your insert statement are you?...'cause that would just be silly... Well if it was in my code I guess I was doing it .. Apparently it's not necessary on AI. Quote Link to comment https://forums.phpfreaks.com/topic/219502-while-looped-insert-is-not-working-as-expected-no-errors/#findComment-1138098 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.