Jump to content

While looped insert is not working as expected. No errors.


Recommended Posts

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');

 

                  $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

                  $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!

You're not seriously including the auto inc field in your insert statement are you?...'cause that would just be silly... :shrug:

 

Well if it was in my code I guess I was doing it  :shrug: .. Apparently it's not necessary on AI.

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.