Jump to content

Recommended Posts

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

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

 

 

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.