Jump to content

inserting into mysql table


grissom

Recommended Posts

Hi all

I'm putting together a little synchronisation routine to transfer some stuff from one table (on localhost) up to a table on the server.

 

First job I did is to pull the info off the table on localhost like this :

 

$localheader_stuff = mysql_query("SELECT * FROM audit_header");
$ii = 0;
while($localheader_row = mysql_fetch_array($localheader_stuff)) $localheader_line[$ii++] = $localheader_row;

 

This has now pulled the data out of the local table and stored it in a series of arrays which I can access (and I have tested using 'echo') by specifying 2 dimensions

eg  echo $localheader_line[0]['user'];  // to get the user field from the first record.

 

So far so good !  Now to INSERT it into the server table.  I connect up and go through each line of data at a time like this :

 

for ($kk =0; $kk < $ii; $kk++) {     // $ii is the number of lines plus one (see bit of code above)
$success = mysql_query("INSERT INTO audit_header (user, zone) VALUES ('$localheader_line[$kk][user]', '$localheader_line[$kk][zone]')"); 
}

 

But it's not working !!  Somewhere I think I've got myself in a twist with some inverted commas or brackets but cannot work out how.

 

help please !  many thanks !!

Link to comment
https://forums.phpfreaks.com/topic/151906-inserting-into-mysql-table/
Share on other sites

So far I've got round it by concatenating a string made up of the bits like

 

$query = "INSERT INTO audit_header (user, zone) VALUES ('" . $localheader_line[$kk]['user']. "', '" . $localheader_line[$kk] . "',       )"      .. // etc  etc

 

and then running $success = mysql_query($query);

 

If anyone else has any better ideas, please let me know, thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.