Use Array to Update DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slash85
Forum Newbie
Posts: 18
Joined: Fri Feb 03, 2006 12:02 pm

Use Array to Update DB

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your update replaces all records where a name is equal to the string zero.
Post Reply