Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having trouble using text file input

Status
Not open for further replies.

jisoo23

Programmer
Joined
Jan 27, 2004
Messages
192
Location
US
Hello all,

I'm trying to run a series of database SQL update statements utilizing a text file read in via PHP. I can get the lines to print out on the web browser but it does not seem to execute my update statement. Here is my code:
Code:
$lines = file('newlist.txt');

foreach ($lines as $line){
	$update = pg_query($conn, "UPDATE table1 SET field1 = 't' WHERE field2 = '$line'");
}

Can anyone tell me what's going on? It seems simple to me but just doesn't want to work.

Thanks,
Jisoo23
 
Nevermind, I figured it out. Turns out it was just an extra whitespace at the end of $line. Solved it with trim(). Don't you just hate those little errors?? Drives me nuts sometimes.

Thanks Anyway All!
 
Hi Jisoo23

I don't think it was your error - I just had a very similar problem and also had to fix a PHP/MySQL script by inserting a trim() to trim the variable before interrogating the database.

What is puzzling me is that the program had worked for months perfectly but just ceased to work for no apparent reason on or around 12th March and this trimming was the only solution.

Just thought you might like to know - I still have no idea why it suddenly required the trim() to work.

Regards,
nandina
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top