1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| <?php
$bWrite = false;
$zMsg = "";
if ($iFd = fopen ("fichier.csv", "r")) // mode lire and ecrire
{
while (!feof ($iFd))
{
$zLine = fgets ($iFd) ;
if ($zLine != "")
{
$zLine = strtolower($zLine);
$tmpArray = array();
$tmpArray = explode (",", $zLine) ;
$iDim = 0;
while($iDim < count($tmpArray))
{
if($tmpArray[$iDim] != "")
{
list ($zNom, $zPrenom, $zSexe, $zAdresse, $iAge, $zProfession, $zMail) = explode (";", $tmpArray[$iDim]) ;
if(isset($_POST['zNom']))
{
if($zNom == strtolower(trim($_POST['zNom'])) && $zPrenom == strtolower(trim($_POST['zPrenom'])))
{
$zMsg = "Donnée existante! veuiller réinsérer";
$bWrite = true;
}
}
}
$iDim++;
}
}
}
}
fclose($iFd);
if ($iFd = fopen ("fichier.csv", "a"))
{ // mode Write and Read
if($bWrite == false){
if(isset($_POST['zNom']))
{
$somecontent = $_POST['zNom'].";".$_POST['zPrenom'].";".$_POST['zSexe'].";".$_POST['iAge'].";".$_POST['zMail'].",";
fwrite($iFd, $somecontent);
$zMsg = "enregistrement réussie";
}
}
fclose($iFd);
}
?>
<html>
<head>
<title>FORMULAIRE</title>
</head>
<body>
<center>
<form name="MyForm" method="post" actionfiltered="form.php" onfiltered="return verifSubmitData();">
<table class="contenant">
<tr><td>
<table width="400" border="0" class="form">
<tr>
<td colspan="2" align="center" class="header">SAISIR LES INFORMATIONS</td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
<tr>
<td>Nom : </td>
<td><input name="zNom" type="text" id="fname" class="inputStyle" onFocus = "clearBox(this);"/></td>
</tr>
<tr>
<td>Prénom : </td>
<td><input name="zPrenom" type="text" id="lname" class="inputStyle" onFocus = "clearBox(this);"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<table width="100%" border="0" cellspadding="0" cellspacing="0">
<tr>
<td>Masculin :</td>
<td width="15%"><input name="zSexe" type="radio" value="M" checked/></td>
<td>Féminin :</td>
<td width="15%"><input name="zSexe" type="radio" value="F"/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Age : </td>
<td><input name="iAge" type="text" id="address" class="inputStyle" onfiltered=" return VerifyAnswer(event);" onFocus = "clearBox(this);"/></td>
</tr>
<tr>
<td>E-mail : </td>
<td><input name="zMail" type="text" class="inputStyle" onFocus = "clearBox(this);"/></td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="ENREGISTRER" class="button"/></td>
</tr>
<?if($zMsg != ""){
print("<tr><td colspan=\"2\" align=\"center\">$zMsg</td></tr>");
}
?>
<tr>
<td colspan="2" align="center"><a href="liste.php" >AFFICHAGE UTILISATEURS</a></td>
</tr>
</table>
</td></tr>
</table>
</form>
</center>
</body>
</html> |
Partager