I have the following code that is giving me a lot of problems.
Whenever it writes to the text file, it is writing the entry twice.
I have traced the code several times, and I am not getting anywhere with it.
Code follows:
//DB CONNECTION (Using my connection class)
INCLUDE("dbcon.php");
$dbo = New DbConnect(PENS);
//Query Database
$sql = "SELECT * FROM tblMembers";
$results = mysql_query($sql);
//Create file and prepare it to be written to
$filename = PENS_MEMBERS.".txt";
IF($handle = fopen($filename,"w"))
{
//Now Write the Data to the File by looping through each record and write to file
$data = "";
//debug// $testObj = mysql_fetch_object($results);
//debug// print_r($testObj);
WHILE($item = mysql_fetch_object($results))
{
$hpw = md5($item->Pword);
$data .= $item->Fname." ".$item->Lname."|".$item->Email."|".$hpw."\r\n";
echo $data."<br>";
IF(!fwrite($handle,$data))
{
PRINT("<h2>ERROR!</h2><br>There was a problem with the Write Operation!");
}//end if
}//end while
PRINT("<h2>SUCCESS!</h2><br>The file should be ready for use!");
}//end if
ELSE
{
PRINT("<h2>ERROR!</h2><br>There was a problem with the File Creation Operation!<br><br>Make sure the file does not already exist.");
}//end else
Can someone please help me see where I am going wrong on this?
-Thanks
Tony