probleme pour modifier fichier.txt

Eléphant du PHP | 181 Messages

09 mars 2006, 15:45

ca m'enleve le pass et login mais ca me rajoute une ligne blanche hors je voudrais pas cette ligne blanche. rien a la place....

et pourkoi il me rajoute le dernier login et pass lorsque je fais un delete??

code php:
$test = file_get_contents($fichier);

if (isset($_POST['Submit2'])) {
	$insertOk2 = true;
	
	if (empty($_POST['login'])) {
		$insertOk = false;
		echo '<div align="center" style="color:#FF0000">the login is obligatory.</div>'.'<br>';
	}
	
	if (empty($_POST['pass'])) {
		echo '<div align="center" style="color:#FF0000">the pass is obligatory.</div>'.'<br>';
		$insertOk = false;
	}
	
	if ($insertOk2) {
		
		$test = str_replace($login.':'.$pass, ' ', $test);
		$fp = fopen($fichier,"r+");
		fwrite($fp,$test);		
	}
}

if (isset($_POST['Submit'])) {
	$insertOk = true;
	
	if (empty($_POST['login'])) {
		$insertOk = false;
		echo '<div align="center" style="color:#FF0000">the login is obligatory.</div>'.'<br>';
	}
	
	if (empty($_POST['pass'])) {
		echo '<div align="center" style="color:#FF0000">the pass is obligatory.</div>'.'<br>';
		$insertOk = false;
	}
	
	if ($insertOk) {
		$text = "\r\n".trim($login).":".trim($pass);
		$handle = fopen($fichier, 'a');
		fwrite($handle, $text);
		$login = '';
		$pass = '';
		$_POST['login'] = '';
		$_POST['pass'] = '';	
	}
}

if (file_exists($fichier)) { 
	$tableau = file($fichier); 

	while(list($cle,$val) = each($tableau)) {
   		echo $val."<br>";
		$tab .= $val;
	} 
}
et mon formulaire:

Code : Tout sélectionner

<form name="form1" method="post" action=""> <table width="30%" > <tr> <td width="6%"><strong>Login:</strong></td> <td width="94%"><input type="text" name="login" value="<?php echo $login?>"></td> </tr> <tr> <td><strong>Pass:</strong></td> <td><input type="text" name="pass" value="<?php echo $pass?>"></td> </tr> <tr> <td> <div align="right"> <input type="submit" name="Submit" value="New"> </div> </td> <td> <input type="hidden" name="i" value="<?php echo $i?>"> <input type="submit" name="Submit2" value="Delete"> </td> </tr> </table> </form>
et j'aurais pas de soucy avec le codage des pass htpass lors de la suppression???

Eléphant du PHP | 181 Messages

16 mars 2006, 10:15

personne ne peut m'aider???

j'ai tjrs ce soucy...

merci d'avance . . .

Eléphant du PHP | 181 Messages

20 mars 2006, 10:32

trouver une autre solution....

vous pouvez mettre delestage et resolu.
merci d'avance