Erreurs avec fputs
Résolu
Tobi86
Messages postés
450
Statut
Membre
-
ElementW Messages postés 5690 Statut Contributeur -
ElementW Messages postés 5690 Statut Contributeur -
Bonsoir a toues, voilà je ne comprends pas pourquoi mon programme ne fonctionne pas ... Pourriez-vous m'éclairer ?
--
Tobi.
"Trois savoirs gouvernent le monde : le savoir, le savoir-vivre et le savoir-faire,
Mais le dernier souvent tient lieu des deux autres."
<?php
include("connexion.php");
$myfile="list-logs.php";
$req="SELECT DISTINCT id, name, first_name, mail, login, password FROM users_profs";
$res = $connect->query($req);
//var_dump($req);
$i=1;
$fichier = 'chemin_du_fichier/fichier.txt';
if( file_exists ( $myfile))
unlink( $myfile );
//Traitement du résultat
while($row=$res->fetch(PDO::FETCH_ASSOC))
{
fputs($myfile, "$id".$i."=".$row['id']."\n");
fputs($myfile, "$name".$i."=".$row['name']."\n");
fputs($myfile, "$firstName".$i."=".$row['first_name']."\n");
fputs($myfile, "$mail".$i."=".$row['mail']."\n");
fputs($myfile, "$login".$i."=".$row['login']."\n");
fputs($myfile, "$password".$i."=".$row['password']."\n");
$i=$i+1;
}
?>
--
Tobi.
"Trois savoirs gouvernent le monde : le savoir, le savoir-vivre et le savoir-faire,
Mais le dernier souvent tient lieu des deux autres."
2 réponses
-
'lut,
fputs
prend un descripteur de fichier en premier paramètre, pas le nom du fichier. Donc il faut faire unfopen
et unfclose
pour que ça marche:$myfile=fopen("list-logs.php", "w"); ... // Le reste de ton code ... fclose($myfile); -
PHP Warning: file_exists() expects parameter 1 to be string, resource given in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 12 PHP Notice: Undefined variable: id in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 19 PHP Notice: Undefined variable: name in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 20 PHP Notice: Undefined variable: firstName in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 21 PHP Notice: Undefined variable: mail in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 22 PHP Notice: Undefined variable: login in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 23 PHP Notice: Undefined variable: password in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 24 PHP Notice: Undefined variable: id in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 19 PHP Notice: Undefined variable: name in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 20 PHP Notice: Undefined variable: firstName in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 21 PHP Notice: Undefined variable: mail in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 22 PHP Notice: Undefined variable: login in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 23 PHP Notice: Undefined variable: password in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 24 PHP Notice: Undefined variable: id in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 19 PHP Notice: Undefined variable: name in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 20 PHP Notice: Undefined variable: firstName in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 21 PHP Notice: Undefined variable: mail in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 22 PHP Notice: Undefined variable: login in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 23 PHP Notice: Undefined variable: password in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 24 PHP Notice: Undefined variable: id in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 19 PHP Notice: Undefined variable: name in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 20 PHP Notice: Undefined variable: firstName in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 21 PHP Notice: Undefined variable: mail in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 22 PHP Notice: Undefined variable: login in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 23 PHP Notice: Undefined variable: password in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 24 PHP Notice: Undefined variable: id in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 19 PHP Notice: Undefined variable: name in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 20 PHP Notice: Undefined variable: firstName in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 21 PHP Notice: Undefined variable: mail in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 22 PHP Notice: Undefined variable: login in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 23 PHP Notice: Undefined variable: password in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 24 PHP Notice: Undefined variable: id in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 19 PHP Notice: Undefined variable: name in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 20 PHP Notice: Undefined variable: firstName in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 21 PHP Notice: Undefined variable: mail in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 22 PHP Notice: Undefined variable: login in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 23 PHP Notice: Undefined variable: password in /home/thibaultc/Documents/www/appli/log/actua-list-logs.php on line 24
-
Il faut que tu changes tes doubles guillemets en guillemets simples ('), sinon PHP essaie d'interpréter les variables dedans, d'où la masse d'erreurs.
Pour l'erreur dufile_exists()
; reviens à ton code précédent et changes-le comme ceci:$myfilename="list-logs.php"; ... if( file_exists ( $myfilename)) unlink( $myfilename ); $myfile=fopen("list-logs.php", "w"); ... // traitement ... fclose($myfile); -
Super ! Merci beaucoup ça fonctionne ! mais j'ai une dernière petite question, est ce que si je met mes
\n
entre double cottes, j'aurais mon retour à la ligne ? parce que actuellement ça m'écrit les données comme ceci :
$password1=63a9f0ea7bb98050796b649e85481845\n$id2=2
au lieu de :
$password1=63a9f0ea7bb98050796b649e85481845
$id2=2 -
-