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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.