Page 1 of 1

Use Array to Update DB

Posted: Tue Feb 27, 2007 3:25 pm
by slash85
Hi,

I'm using the below to open a text file read all the lines into an array which i then echo out just to make sure the array contains what i want (which it does) But when i try to do an mysql_query update with the array it only pulls the last name from the text file eg:

Text file has 10 names
The echo, echo's the 10 names
The update inserts 10 Johns into the database

Can anyone give me any pointers?

Code: Select all

<?php

$fc=file("test.txt");



foreach($fc as $line)
{


echo $line;

$result = mysql_query("UPDATE test SET Name='$line' WHERE Name='0'") or die(mysql_error());          

}

?>
Thanks for any help,
Slash.

Posted: Tue Feb 27, 2007 4:04 pm
by feyd
Your update replaces all records where a name is equal to the string zero.