clay1 Posted August 9, 2009 Share Posted August 9, 2009 This is related but a different issue than my other thread so I started a new topic When I run my script, I am ending up with a table which looks like this: a b c d a NULL NULL NULL NULL b NULL NULL NULL NULL c NULL $insertSql = "INSERT INTO test ($fields[$col]) VALUES ('$vars[$col]')"; $result = pg_query($conn, $insertSql); The echoed statement lines everything up correctly. Column A B C have the appropriate values and so forth echo $insertSql; Displays: INSERT INTO test (a) VALUES ('a')INSERT INTO test (b) VALUES ('b')INSERT INTO test (c) VALUES ('c') Each time it's moving down a row and over 1 column and inserting null values, instead of over each column and then down a row with the correct values. I imagine this is somehow related to my loops, but can't figure out why it would echo correctly but not hit the DB correct Link to comment https://forums.phpfreaks.com/topic/169460-records-inserted-diagonally-rather-than-across/ Share on other sites More sharing options...
RestlessThoughts Posted August 9, 2009 Share Posted August 9, 2009 Just insert all same row values all at once. "INSERT INTO `table` (`a`,`b`,`c`) VALUES ('a','b','c')"; // AKA "INSERT INTO `table` (`$fields[$col]`,`$fields[$col+1]`,`$fields[$col+2]`) VALUES ('$fields[$col]','$fields[$col+1]','$fields[$col+2]')"; Link to comment https://forums.phpfreaks.com/topic/169460-records-inserted-diagonally-rather-than-across/#findComment-894078 Share on other sites More sharing options...
clay1 Posted August 11, 2009 Author Share Posted August 11, 2009 I basically scrapped everything and started over and got it working. Link to comment https://forums.phpfreaks.com/topic/169460-records-inserted-diagonally-rather-than-across/#findComment-895307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.