Ache Posted January 16, 2009 Share Posted January 16, 2009 Where am I going wrong? First part of the code is working fine but when I press the "Activate" link, the function runs but it only puts 2 in the "out.txt" file and does not add anything to "$dataUsers". <?php include ("../config.php");// Open the user database and check if there is a account waiting for approval $fh = fopen("../$dataNew",'r') or die("can't open file"); while (!feof($fh)) { $tempData = fgetcsv($fh,","); if ($tempData[0] == 1) { echo "<table cellspacing=\"2\" cellpadding=\"2\" border=\"0\">\n"; echo "<tr><td align=\"right\">Level : </td>\n"; echo " <td>$tempData[0]</td></tr>\n"; echo "<tr><td align=\"right\">Gebruikersnaam : </td>\n"; echo " <td>$tempData[1]</td></tr>\n"; echo "<tr><td align=\"right\">Wachtwoord : </td>\n"; echo " <td>$tempData[2]</td></tr>\n"; echo "<tr><td align=\"right\">Voornaam : </td>\n"; echo " <td>$tempData[3]</td></tr>\n"; echo "<tr><td align=\"right\">Achternaam : </td>\n"; echo " <td>$tempData[4]</td></tr>\n"; echo "<tr><td align=\"right\">Straat : </td>\n"; echo " <td>$tempData[5]</td></tr>\n"; echo "<tr><td align=\"right\">Huisnummer : </td>\n"; echo " <td>$tempData[6]</td></tr>\n"; echo "<tr><td align=\"right\">Toevoeging : </td>\n"; echo " <td>$tempData[7]</td></tr>\n"; echo "<tr><td align=\"right\">Postkode : </td>\n"; echo " <td>$tempData[8]</td></tr>\n"; echo "<tr><td align=\"right\">Plaats : </td>\n"; echo " <td>$tempData[9]</td></tr>\n"; echo "<tr><td align=\"right\">E-mail : </td>\n"; echo " <td>$tempData[10]</td></tr>\n"; echo "<tr><td align=\"right\">Geboorte datum : </td>\n"; echo " <td>$tempData[11]</td></tr>\n"; echo "<tr><td align=\"right\">Telefoon : </td>\n"; echo " <td>$tempData[12]</td></tr>\n"; echo "<tr><td align=\"right\">Toestel : </td>\n"; echo " <td>$tempData[13]</td></tr>\n"; echo "<tr><td align=\"right\">Geslacht : </td>\n"; echo " <td>$tempData[14]</td></tr>\n"; echo "<tr><td align=\"right\">Credits : </td>\n"; echo " <td>$tempData[15]</td></tr>\n"; echo "<tr><td align=\"right\">Aanmeld datum : </td>\n"; echo " <td>$tempData[16]</td></tr>\n"; echo "</table>\n"; } } fclose($fh);?><a href="<?php echo("$PHP_SELF?execute=myfunction")?>"><b>Activate</b></a><p><?php if ( isset($execute) ){approved();} function approved() {// Change user status to active $target = 'out.txt'; $sh = fopen("../$dataUsers",'r') or die("can't open file"); $th = fopen($target, 'w'); while (!feof($sh)) { $tempDat = fgetcsv($sh,","); if ($tempDat[1] == $tempData[1]) { $tempDat[0] = 2; fputcsv($th,$tempDat); } else { fputcsv($th,$tempDat); } } fclose($sh); fclose($th); // delete old source file unlink($sh); // rename target file to source file rename($target, $dataUsers); }?> Link to comment Share on other sites More sharing options...
Ache Posted January 17, 2009 Author Share Posted January 17, 2009 I solved it. This is the change I made. No seperate file that holds new users, just 1 file with the users and then change the status data ($tempdata[0]) I hope This little code is helpfull to others. <a href="<?php echo("$PHP_SELF?execute=myfunction")?>"><b>Activate</b></a><p><?php if ( isset($execute) ) { $target = 'out.txt'; $fh = fopen($dataUsers,'r') or die("can't open file"); $th = fopen($target, 'w'); while (!feof($fh)) { $tempData = fgetcsv($fh,","); if ($tempData[1] == $name) { $tempData[0] = 2; fputcsv($th,$tempData); } else { fputcsv($th,$tempData); } } fclose($fh); fclose($th);// delete old source file unlink($dataUsers);// rename target file to source file rename($target, $dataUsers); }?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.