Recuperer donnée dans un fichier texte

Petit nouveau ! | 3 Messages

06 déc. 2010, 15:34

Bonjour,
Cela fait plusieurs heures que je recherche sans succes un code en php.
Je crais un sondage avec photos pour un concours photo . avec des boutons radios.

Une fois que le visteur clique sur voter, j'aimerais que dans un fichier texte, ou plusieurs ( le plus facile ) pour chaque candidat, il y ai ecrit le nombre de vote. ce fichier ne serait visible que par moi.

je cherche partout un code comme celui là, je ne trouve pas

J'ai neanmoins essayé ceci :
<tr valign="middle">
      <td align="center" valign="middle"><div align="center">Aicha  
          <input type='radio' name='vote' value='1'></div></td>
      <td align="center" valign="middle"><div align="center"> Assa  
          <input type='radio' name='vote' value='2'></div></td>
      <td align="center" valign="middle"><div align="center"> Zahra  
          <input type='radio' name='vote' value='3'></div></td>
      <td align="center" valign="middle"><div align="center"> Tracy  
          <input type='radio' name='vote' value='4'></div></td>
      <td align="center" valign="middle"><div align="center"> Sarah  
          <input type='radio' name='vote' value='5'></div></td>
      <td align="center" valign="middle"><div align="center"> Safietou  
          <input type='radio' name='vote' value='6'></div></td>
      <td align="center" valign="middle"><div align="center"> Sandra  
          <input type='radio' name='vote' value='7'></div></td>
      <td align="center" valign="middle"><div align="center"> Rania  
          <input type='radio' name='vote' value='8'></div></td>
    </tr>
<form method="post" action="vers_la_page_php.php">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Document sans titre</title>
</head>

<body>
<?php

switch ($vote) // on indique sur quelle variable on travaille
{ 
case 1: // dans le cas où $note vaut 1

$monfichier = fopen('candidate_1.txt', 'r+');
 
$votes = fgets($monfichier); // On lit la première ligne (nombre de pages vues)
$votes++; // On augmente de 1 ce nombre de pages vues
fseek($monfichier, 0); // On remet le curseur au début du fichier
fputs($monfichier, $votes); // On écrit le nouveau nombre de pages vues

fclose($monfichier);
break;

case 2: // dans le cas où $note vaut 5
$monfichier = fopen('candidate_2.txt', 'r+');
 
$votes = fgets($monfichier); // On lit la première ligne (nombre de pages vues)
$votes++; // On augmente de 1 ce nombre de pages vues
fseek($monfichier, 0); // On remet le curseur au début du fichier
fputs($monfichier, $votes); // On écrit le nouveau nombre de pages vues
 
fclose($monfichier);
break;

case 3: // dans le cas où $note vaut 7
$monfichier = fopen('candidate_3.txt', 'r+');
 
$votes = fgets($monfichier); // On lit la première ligne (nombre de pages vues)
$votes++; // On augmente de 1 ce nombre de pages vues
fseek($monfichier, 0); // On remet le curseur au début du fichier
fputs($monfichier, $votes); // On écrit le nouveau nombre de pages vues
 
fclose($monfichier);
break;

case 4: // etc etc
$monfichier = fopen('candidate_4.txt', 'r+');
 
$votes = fgets($monfichier); // On lit la première ligne (nombre de pages vues)
$votes++; // On augmente de 1 ce nombre de pages vues
fseek($monfichier, 0); // On remet le curseur au début du fichier
fputs($monfichier, $votes); // On écrit le nouveau nombre de pages vues
 
fclose($monfichier);
break;


default:


}
?>
</body>
</html>
Ca ne fonctionne pourtant pas .. Merci beaucoup celà fait plusieurs jours que je cherche !

Eléphanteau du PHP | 21 Messages

06 déc. 2010, 16:13

Code : Tout sélectionner

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Document sans titre</title> </head> <body> <?php if (isset($_POST['vote'])) { switch ($_POST['vote']) // on indique sur quelle variable on travaille { case 1: // dans le cas où $note vaut 1 $fp = fopen('candidate_1.txt', 'r+'); break; case 2: // dans le cas où $note vaut 5 $fp = fopen('candidate_2.txt', 'r+'); break; case 3: // dans le cas où $note vaut 7 $fp = fopen('candidate_3.txt', 'r+'); break; case 4: // etc etc $fp = fopen('candidate_4.txt', 'r+'); break; default: } $votes = (int)fgets($fp,255); $votes++; fseek($fp,0); fputs($fp,$votes); fclose($fp); } ?> <form method="post" action="#"> <table> <tr valign="middle"> <td align="center" valign="middle"><div align="center">Aicha <input type='radio' name='vote' value='1'></div></td> <td align="center" valign="middle"><div align="center"> Assa <input type='radio' name='vote' value='2'></div></td> <td align="center" valign="middle"><div align="center"> Zahra <input type='radio' name='vote' value='3'></div></td> <td align="center" valign="middle"><div align="center"> Tracy <input type='radio' name='vote' value='4'></div></td> <td align="center" valign="middle"><div align="center"> Sarah <input type='radio' name='vote' value='5'></div></td> <td align="center" valign="middle"><div align="center"> Safietou <input type='radio' name='vote' value='6'></div></td> <td align="center" valign="middle"><div align="center"> Sandra <input type='radio' name='vote' value='7'></div></td> <td align="center" valign="middle"><div align="center"> Rania <input type='radio' name='vote' value='8'></div></td> <td align="center" valign="middle"><div align="center"><input type="submit" value="Voter" /></td> </tr> </table> </form> </body> </html>

devlop78
Invité n'ayant pas de compte PHPfrance

06 déc. 2010, 20:46

Comme dirait stealth35 :
Utilisez file_get_contents() ;)

Petit nouveau ! | 3 Messages

06 déc. 2010, 21:50

Merci, j'ai essayé comme ci dessous et pourtant mon fichier texte reste toujours vierge . (je lui ai mis les autorisations 777)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0049)http://www.missafriquemontreal.ca/candidates.html -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>MISS AFRIQUE MONTREAL</title>
<style type="text/css">
<!--




body {
	background-color: #000033;
	background-image: url(bgd.jpg);
	background-repeat: no-repeat;
	background-position: top center;
}
body,td,th {
	font-family: Verdana;
	font-size: 10px;
	color: #FFFFFF;
}
.style5 {color: #5F6D78}
-->
</style>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}
//-->
</script>
<link rel="icon" type="image/png" href="http://www.missafriquemontreal.ca/favicon.png"></head>





<body onload="MM_preloadImages('Menu/acc0.jpg','MISS AFRIQUE MONTREAL_files/Menu/acc0.jpg')">
<div align="center">
  <p><img src="./MISS AFRIQUE MONTREAL_files/top logo.jpg" width="978" height="178"><br>      
      <br>
    <a href="http://www.missafriquemontreal.ca/index.html"><img src="./MISS AFRIQUE MONTREAL_files/acc.jpg" width="105" height="45" border="0" id="Image1" onmouseover="MM_swapImage('Image1','','Menu/acc0.jpg',1)" onmouseout="MM_swapImgRestore()"></a><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image101','','MISS AFRIQUE MONTREAL_files/Menu/acc0.jpg',1)"><img src="MISS AFRIQUE MONTREAL_files/acc.jpg" name="Image101" width="105" height="45" border="0" id="Image101" /></a><a href="./MISS AFRIQUE MONTREAL_files/MISS AFRIQUE MONTREAL.html"><img src="./MISS AFRIQUE MONTREAL_files/cand0.jpg" width="132" height="45" border="0" id="Image2" onmouseover="MM_swapImage('Image2','','Menu/cand0.jpg',1)" onmouseout="MM_swapImgRestore()"></a><a href="http://www.missafriquemontreal.ca/gala.html"><img src="./MISS AFRIQUE MONTREAL_files/gala.jpg" width="73" height="45" border="0" id="Image3" onmouseover="MM_swapImage('Image3','','Menu/gala0.jpg',1)" onmouseout="MM_swapImgRestore()"></a><a href="http://www.missafriquemontreal.ca/deroulement.html"><img src="./MISS AFRIQUE MONTREAL_files/der.jpg" name="Image8" width="146" height="45" border="0" id="Image8" onmouseover="MM_swapImage('Image8','','Menu/der0.jpg',1)" onmouseout="MM_swapImgRestore()"></a><a href="http://www.missafriquemontreal.ca/partenaires.html"><img src="./MISS AFRIQUE MONTREAL_files/part.jpg" width="132" height="45" border="0" id="Image9" onmouseover="MM_swapImage('Image9','','Menu/part0.jpg',1)" onmouseout="MM_swapImgRestore()"></a><a href="http://www.missafriquemontreal.ca/videos.html"><img src="./MISS AFRIQUE MONTREAL_files/vid.jpg" name="Image4" width="85" height="45" border="0" id="Image4" onmouseover="MM_swapImage('Image4','','Menu/vid0.jpg',1)" onmouseout="MM_swapImgRestore()"></a><a href="http://missafriquemontreal.blogspot.com/" target="_blank"><img src="./MISS AFRIQUE MONTREAL_files/blog.jpg" width="75" height="45" border="0" id="Image5" onmouseover="MM_swapImage('Image5','','Menu/blog0.jpg',1)" onmouseout="MM_swapImgRestore()"></a><a href="http://www.missafriquemontreal.ca/aboutus.html"><img src="./MISS AFRIQUE MONTREAL_files/aboutus.jpg" alt="" width="106" height="45" border="0" id="Image6" onmouseover="MM_swapImage('Image6','','Menu/aboutus0.jpg',1)" onmouseout="MM_swapImgRestore()"></a><a href="http://www.missafriquemontreal.ca/contact.html"><img src="./MISS AFRIQUE MONTREAL_files/cont.jpg" width="112" height="45" border="0" id="Image7" onmouseover="MM_swapImage('Image7','','Menu/cont0.jpg',1)" onmouseout="MM_swapImgRestore()"></a><br>
  <br>
  <span class="style5">Cliquez sur les photos pour</span><span class="style5"> les agrandir</span></p>
  <?php

if (isset($_POST['vote'])) {
switch ($_POST['vote']) // on indique sur quelle variable on travaille
{
case 1: // dans le cas où $note vaut 1

$fp = fopen('candidate_1.txt', 'r+');


break;

case 2: // dans le cas où $note vaut 5
$fp = fopen('candidate_2.txt', 'r+');

break;

case 3: // dans le cas où $note vaut 7
$fp = fopen('candidate_3.txt', 'r+');

break;

case 4: // etc etc
$fp = fopen('candidate_4.txt', 'r+');

break;


default:


}

$votes = (int)fgets($fp,255); 
$votes++; 
fseek($fp,0); 
fputs($fp,$votes); 
fclose($fp); 
}
?>
  <table width="977" border="0" cellspacing="2" cellpadding="0">
    <tbody><tr valign="middle">
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Aicha - Cameroun.JPG" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Aicha - Cameroun.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/Cameroon.jpg" width="100" height="30"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Assa - mali.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Assa - mali.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/mali.jpg" width="100" height="30"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Zara - maroc.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Zara - maroc.JPG','','width=810,height=510')"></a><br>
          <img src="./MISS AFRIQUE MONTREAL_files/MAroc.jpg" width="100" height="30" border="0"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Tracy - benin.JPG" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Tracy - benin.JPG','','width=810,height=510')"></a><br>
          <img src="./MISS AFRIQUE MONTREAL_files/benin.jpg" width="100" height="30" border="0"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Sarah - cote divoire.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Sarah - cote divoire.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/Cote d'Ivoire.jpg" width="100" height="30"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Safietou - guinee.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Safietou - guinee.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/GUINEE .jpg" width="100" height="30"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Sandra - rwanda.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Sandra - rwanda.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/rwanda.jpg" width="100" height="30"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Rania - cote divoire.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Rania - cote divoire.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/Cote d'Ivoire.jpg" width="100" height="30"></div></td>
    </tr>
    
    <tr valign="middle">
      <td align="center" valign="middle"><div align="center">Aicha  
          <input type="radio" name="vote" value="1"></div></td>
      <td align="center" valign="middle"><div align="center"> Assa  
          <input type="radio" name="vote" value="2"></div></td>
      <td align="center" valign="middle"><div align="center"> Zahra  
          <input type="radio" name="vote" value="3"></div></td>
      <td align="center" valign="middle"><div align="center"> Tracy  
          <input type="radio" name="vote" value="4"></div></td>
      <td align="center" valign="middle"><div align="center"> Sarah  
          <input type="radio" name="vote" value="5"></div></td>
      <td align="center" valign="middle"><div align="center"> Safietou  
          <input type="radio" name="vote" value="6"></div></td>
      <td align="center" valign="middle"><div align="center"> Sandra  
          <input type="radio" name="vote" value="7"></div></td>
      <td align="center" valign="middle"><div align="center"> Rania  
          <input type="radio" name="vote" value="8"></div></td>
    </tr>
    <tr valign="middle">
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Cathy - senegal.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Cathy - senegal.JPG','','width=810,height=510')"></a><br>
          <img src="./MISS AFRIQUE MONTREAL_files/SENEGAL.jpg" width="100" height="30" border="0"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Ndeye - mali.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Ndeye - mali.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/mali.jpg" width="100" height="30"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Majda - algerie.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Majda - algerie.JPG','','width=810,height=510')"></a><br>
          <img src="./MISS AFRIQUE MONTREAL_files/ALGERIE .jpg" width="100" height="30" border="0"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Lowa -congo.JPG" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Lowa -congo.JPG','','width=810,height=510')"></a><br>
          <img src="./MISS AFRIQUE MONTREAL_files/RDC.jpg" width="100" height="30" border="0"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Lalla Aicha 2 - mali.JPG" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Lalla Aicha 2 - mali.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/mali.jpg" width="100" height="30"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Habi 2 - Cameroun.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Habi 2 - Cameroun.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/Cameroon.jpg" width="100" height="30"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Gladys - burkina.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Gladys - burkina.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/BURKINA.jpg" width="100" height="30"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Gabriela - congo.JPG" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Gabriela - congo.JPG','','width=810,height=510')"><br>
      </a><img src="./MISS AFRIQUE MONTREAL_files/RDC.jpg" width="100" height="30" border="0"></div></td>
    </tr>
    <tr valign="middle">
      <td><div align="center"> Cathy  
          <input type="radio" name="vote" value="9"></div></td>
      <td><div align="center"> Ndeye Awa  
          <input type="radio" name="vote" value="10"></div></td>
      <td><div align="center"> Majda  
          <input type="radio" name="vote" value="11"></div></td>
      <td><div align="center"> Lowa  
          <input type="radio" name="vote" value="12"></div></td>
      <td><div align="center"> Lalla Aicha  
          <input type="radio" name="vote" value="13"></div></td>
      <td><div align="center"> Habi  
          <input type="radio" name="vote" value="14"></div></td>
      <td><div align="center"> Gwladys  
          <input type="radio" name="vote" value="15"></div></td>
      <td><div align="center">Gabriela  
          <input type="radio" name="vote" value="16"></div></td>
    </tr>
    <tr valign="middle">
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><br>
      </a></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/faridath.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/faridath.JPG','','width=810,height=510')"></a><br>
          <img src="./MISS AFRIQUE MONTREAL_files/benin.jpg" width="100" height="30" border="0"><br>
      </div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Elisa - senegal.JPG" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Elisa - senegal.JPG','','width=810,height=510')"></a><br>
          <img src="./MISS AFRIQUE MONTREAL_files/SENEGAL.jpg" width="100" height="30"><br>
      </div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/chatou.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/chatou.JPG','','width=810,height=510')"></a><br>
          <img src="./MISS AFRIQUE MONTREAL_files/Niger.jpg" width="100" height="30"><br>
      </div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Fatou - mali.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Fatou - mali.JPG','','width=810,height=510')"></a><br>
        <img src="./MISS AFRIQUE MONTREAL_files/mali.jpg" width="100" height="30" border="0"></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Mawa - Guinee.jpg" alt="e" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Mawa - Guinee.JPG','','width=810,height=510')"><br>
</a><img src="./MISS AFRIQUE MONTREAL_files/GUINEE .jpg" alt="e" width="100" height="30"><a href="http://www.missafriquemontreal.ca/candidates.html#"><br>
      </a></div></td>
      <td><div align="center"><a href="http://www.missafriquemontreal.ca/candidates.html#"><img src="./MISS AFRIQUE MONTREAL_files/Consolata.jpg" width="100" height="136" border="0" onclick="MM_openBrWindow('candidate/Consolata.JPG','','width=810,height=510')"></a><br>
        <img src="./MISS AFRIQUE MONTREAL_files/RDC.jpg" width="100" height="30" border="0"></div></td>
      <td><div align="center"></div></td>
    </tr>
    <tr valign="middle">
      <td> <div align="center"></div></td>
      <td><div align="center">Faridath
          <input type="radio" name="vote" value="17">
      </div></td>
      <td><div align="center">Elisa
          <input type="radio" name="vote" value="18">
      </div></td>
      <td><div align="center">Chatou
          <input type="radio" name="vote" value="19">
      </div></td>
      <td><div align="center">Fatou
          <input type="radio" name="vote" value="20">
      </div></td>
      <td><div align="center">Mawa
          <input type="radio" name="vote" value="21">
      </div></td>
      <td><div align="center">Consolata
          <input type="radio" name="vote" value="22">
      </div></td>
      <td><div align="center"></div></td>
    </tr>
  </tbody></table>
  <p>
</p><form method="post" action="#">
  <table align="center" style="font-family:Tahoma; font-size:12pt" width="248" border="0">
<tbody><tr>
  <th align="center"><input type="submit" onclick="MM_popupMsg('Merci. Votre vote a été enregistré avec succès.')" value="  Vote  ">
  </th></tr>
</tbody></table>
</form>
  
  &nbsp;<p></p>
  <p><img src="./MISS AFRIQUE MONTREAL_files/bottombar.jpg" width="976" height="45" border="0" usemap="#Map">
<map name="Map" id="Map"><area shape="rect" coords="862,13,969,32" href="http://www.greenstardesigns.com/" target="_blank">
<area shape="rect" coords="47,4,83,42" href="http://twitter.com/MissAfrikMTL" target="_blank">
<area shape="rect" coords="8,5,42,40" href="http://www.facebook.com/group.php?gid=149233328446982" target="_blank">
</map></p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>


</body></html>

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

06 déc. 2010, 23:04

salut,

pour ton dernier code les radio ne sont pas dans le formulaire.

si tu est en php 5 file_get_contents et file_put_contents devrait aider.

perso je ferais plutôt ainsi
<?php
/*
* 	on travail avec un seul fichier que l'on va appeler vote.txt
* 	Ce fichier contient un tableau sérialisé (plus facile pour travailler
*/

$vote = unserialize (file_get_contents('vote.txt'));
if (isset($_POST['vote'])) {
	if (array_key_exists($_POST['vote'],$vote)){
        //
        $vote[$_POST['vote']]['nbvote']++;
	}
	else {
		$erreur = 'vote impossible';
	}
}
// sauvegarde
file_put_contents('vote.txt',serialize($vote));
//affichage du formulaire
echo '<form action="" method="post">';
foreach($vote as $candidate => $value) {
    echo '<input type="radio" name="vote" value="'.$candidate.'" />'.$value['nom'].'<br />';
}
echo '<input type="submit" value="Vadlider" /></form>';

var_dump($vote);// mis opur vérifier que ça fonctionne correctement
?>
avec $vote qui est comme ceci:

Code : Tout sélectionner

array 0 => array 'nbvote' => int 1 'nom' => string 'Aicha' (length=5) 1 => array 'nbvote' => int 2 'nom' => string 'Assa' (length=4) 2 => array 'nbvote' => int 3 'nom' => string 'Zahra' (length=5) 3 => array 'nbvote' => int 4 'nom' => string 'Tracy' (length=5) 4 => array 'nbvote' => int 5 'nom' => string 'Sarah' (length=5) 5 => array 'nbvote' => int 6 'nom' => string 'Safietou' (length=8) 6 => array 'nbvote' => int 7 'nom' => string 'Sandra' (length=6) 7 => array 'nbvote' => int 8 'nom' => string 'Rania' (length=5)
il te reste à construire l'interface qui va générer le tableau (c'est pas compliqué du tout).
edit : je n'ai pas mis de test sur l'existance du fichier mais ça pourrait être bien (tu ajoute la partis pour remplir le fichier et ton systeme est complet ;))

@+
Il en faut peu pour être heureux ......

Petit nouveau ! | 3 Messages

06 déc. 2010, 23:23

J'ai réussit a faire ce que je voulais :) le tableau, pas encore mon niveau ... il est vrai que ca aurait ete plus pratique mais bon .. avec chaque vote enregistré dans un fichier different ca va aussi .. Mercii