Jump to content

[SOLVED] Read File Help


ErcFrtz

Recommended Posts

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

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?

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.