ErcFrtz Posted October 29, 2009 Share Posted October 29, 2009 Hello all. I am trying to read a tab delimited text file and update fields in an SQL table using the info from the file, but the php script isn't reading the file correctly. Do I have something incorrect in my code? <?php $uploadFile = "directory_to_my_file"; $readFile = file($uploadFile); foreach($readFile as $line) { $tmp = explode("\t",$line); $markername = $tmp[0]; $ncbissnum = $tmp[1]; $sql = "SELECT * FROM Marker WHERE MarkerName = '$markername'"; $query = mysql_query($sql, $connect) or die(mysql_error()); while($row = mysql_fetch_assoc($query)) { extract($row); if($row["MarkerName"] == $markername) { $sql2 = "UPDATE Marker SET NCBISSNum='$ncbissnum' WHERE MarkerName='$markername'"; $query2 = mysql_query($sql2, $connect) or die(mysql_error()); $result2 = mysql_fetch_array($query2); } } } ?> Link to comment https://forums.phpfreaks.com/topic/179497-solved-read-file-help/ Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 try echo $line; print_r($tmp); exit; after exploding it, you may need to check what your getting and paste it here Link to comment https://forums.phpfreaks.com/topic/179497-solved-read-file-help/#findComment-947079 Share on other sites More sharing options...
ErcFrtz Posted October 29, 2009 Author Share Posted October 29, 2009 Putting that code in doesn't print anything. I had tried echo $line; before but it doesn't print anything. It seems like the file isn't being read properly and I've rechecked my directory info etc and it's correct which is why I asked if I had a coding problem. Is there a possibility the file is too big? Link to comment https://forums.phpfreaks.com/topic/179497-solved-read-file-help/#findComment-947081 Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 try error_reporting(2047); //right ta the top //inside the loop echo $line; print_r($tmp); die(); have you looked at teh page source to make syure its not outing anything ? Link to comment https://forums.phpfreaks.com/topic/179497-solved-read-file-help/#findComment-947088 Share on other sites More sharing options...
ErcFrtz Posted October 29, 2009 Author Share Posted October 29, 2009 The page source and the the actual page are both blank. Link to comment https://forums.phpfreaks.com/topic/179497-solved-read-file-help/#findComment-947093 Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 The page source and the the actual page are both blank. can you output any php output anywhere else in your system, i mean is there any includes in this file above this ? if not your serve ris messed up Link to comment https://forums.phpfreaks.com/topic/179497-solved-read-file-help/#findComment-947099 Share on other sites More sharing options...
ErcFrtz Posted October 29, 2009 Author Share Posted October 29, 2009 There is authentication code for being logged in also in this script before that which I've listed and everything works right up to the $readFile = file($uploadFile); line. Link to comment https://forums.phpfreaks.com/topic/179497-solved-read-file-help/#findComment-947119 Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 can ytou echo before $readFile = file($uploadFile); what version php you using turn error_reporting on Link to comment https://forums.phpfreaks.com/topic/179497-solved-read-file-help/#findComment-947129 Share on other sites More sharing options...
ErcFrtz Posted October 29, 2009 Author Share Posted October 29, 2009 I solved the problem I was having a different way. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/179497-solved-read-file-help/#findComment-947186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.