Certainly:
<?php
$connID = mysql_pconnect($sqlhost, $sqluser, $sqlpass) or
die($errorMsg[1]."<br>ErrorNo. ".mysql_errno()."<br>MySQL said: ".mysql_error());
mysql_select_db($sqldb, $connID) or
die($errorMsg[2]."<br>ErrorNo. ".mysql_errno()."<br>MySQL said: ".mysql_error());
#source file located in same directory as this script:
$lines = file ('list.txt');
foreach ($lines as $line_num => $line) {
in my phonebook application I was using these 7 fields:
$query = "INSERT INTO ab_records (Department,WorkPh,FirstName,LastName,HomePh,MobilePh,Email1) VALUES ('$array2[0]','$array2[1]','$array2[2]','$array2[3]','$array2[4]','$array2[5]','$array2[6]')";
my source file has each element delimited by comas
$line = trim($line);
$array2 = explode(",", $line);
This is the line that actually launches the query.
You can comment it out if all you want is the next function...
mysql_query($query, $connID);
this is a function I just added to display
the source file lines and replace elements
if needed. I then copy-pasted the output into
the source file itself again. You could you a
file writing command for this of course
$tobereplaced = "none";
$replacement = "";
if ($array2[0] == $tobereplaced){ echo $replacement.","; } else { echo $array2[0].","; }
if ($array2[1] == $tobereplaced){ echo $replacement.","; } else { echo $array2[1].","; }
if ($array2[2] == $tobereplaced){ echo $replacement.","; } else { echo $array2[2].","; }
if ($array2[3] == $tobereplaced){ echo $replacement.","; } else { echo $array2[3].","; }
if ($array2[4] == $tobereplaced){ echo $replacement.","; } else { echo $array2[4].","; }
if ($array2[5] == $tobereplaced){ echo $replacement.","; } else { echo $array2[5].","; }
if ($array2[6] == $tobereplaced){ echo $replacement."<br>"; } else { echo $array2[6]."<br>"; }
}
?>