je crée une nouvelle table id et ip. mais comment je recupere les informations comme id?
merci
Version imprimable
je crée une nouvelle table id et ip. mais comment je recupere les informations comme id?
merci
Tu le fais déja dans ton code actuel.
abon? mais comment je declare ca dans le script pour inséré ip dans la nouvelle table?
je vois pas tres bien la :(
merci
Tu remplaces l'update que tu nous a montré par un insert dans ta nouvelle table.
update me sert à remplacer les valeurs stocké dans les resultats.
insert me servira à ajouter les adresse ip des utilisateur, comment je peux faire ca? ( c ca je vois pas)
merci beaucoup
Je ne vois pas ce qui te bloque.
Tu as juste a ecrire et executer une requete INSERT des valeurs de l'id du sondage et de l'ip du visiteur dans ta nouvelle table.
je vois pas le script a ecrire et la requete , mon probleme?
Tu ne sais pas écrire une requête ?
Le code que tu nous montre n'est pas de toi ?
si le code vient de moi.
mais la je ne vois pas, merci de m'eclairer de me montrer comment on peut faire?
merci bcp
Peux-tu me montrer la structure de ta nouvelle table et ce que tu as déjà ecris pour la requete INSERT ?
pour INSERT:
la table sql:Code:
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 $ip = $_SERVER['REMOTE_ADDR']; echo("<br />" . $ip . "<br />"); $query = "SELECT id FROM $table " ; //echo("<br />" . $query . "<br />"); $result = mysql_query($query); $num = mysql_num_rows($result); if($num) { if ($infos['question'] != "") echo $infos['question'].'<br/>'. ""; if ($infos['proposition1'] != "") echo $infos['proposition1'].'<br/>'. "<input type='radio' name='sondage' value='prop1' id='prop1' /> <label for='prop1'>" .'<img src="copper.jpg" height="10"width="' . $pourcentage_r1 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r1).'%" />.' . round($pourcentage_r1) . "% </label><br />"; if ($infos['proposition2'] != "") echo $infos['proposition2'].'<br/>'. "<input type='radio' name='sondage' value='prop2' id='prop2' /> <label for='prop2'>" .'<img src="copper.jpg" height="10"width="' . $pourcentage_r2 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r2).'%" />.' . round($pourcentage_r2) . "% </label><br />"; if ($infos['proposition3'] != "") echo $infos['proposition3'].'<br/>'. "<input type='radio' name='sondage' value='prop3' id='prop3' /> <label for='prop3'>" .'<img src="copper.jpg" height="10"width="' . $pourcentage_r3 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r4).'%" />.' . round($pourcentage_r3) . "% </label><br />"; if ($infos['proposition4'] != "") echo $infos['proposition4'].'<br/>'. "<input type='radio' name='sondage' value='prop4' id='prop4' /> <label for='prop4'>" .'<img src="copper.jpg" height="10"width="' . $pourcentage_r4 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r4).'%" />.' . round($pourcentage_r4) . "% </label><br />"; if ($infos['proposition5'] != "") echo $infos['proposition5'].'<br/>'. "<input type='radio' name='sondage' value='prop5' id='prop5' /> <label for='prop5'>" .'<img src="copper.jpg" height="10"width="' . $pourcentage_r5 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r5).'%" />.' . round($pourcentage_r5) . "% </label><br />"; exit; } //note importante : s'insere toujours dans un nouveau id// $sql = "INSERT INTO $table1 (ip) VALUES ('$ip') WHERE id="."'" . $numeroDuSondage['nbre_entrees'] . "'"; //mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
merciCode:
1
2
3
4
5
6 CREATE TABLE sondage_lang ( id char(50), ip char(50), PRIMARY KEY(id) );
Il manque l'id du sondage.
CREATE TABLE t_vote (
vote_id int(16) unsigned NOT NULL auto_increment,
sondage_id int(16) unsigned NOT NULL,
vote_ip varchar(15) NOT NULL,
PRIMARY KEY(vote_id)
);
Ca va donner par exemple pour deux votants sur le sondage 12
vote_id - sondage_id - vote_ip
1 - 12 - 143.54.12.17
2 - 12 - 15.54.17.17
si qqn pouvais m'eclaircir sur le script a modifié:
afin de limité une ip par sondageCode:
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 $ip = $_SERVER['REMOTE_ADDR']; echo("<br />" . $ip . "<br />"); $query = "SELECT id FROM $table " ; //echo("<br />" . $query . "<br />"); $result = mysql_query($query); $num = mysql_num_rows($result); if($num) { if ($infos['question'] != "") echo $infos['question'].'<br/>'. ""; if ($infos['proposition1'] != "") echo $infos['proposition1'].'<br/>'. "<input type='radio' name='sondage' value='prop1' id='prop1' /> <label for='prop1'>" .'<img src="copper.jpg" height="10"width="' . $pourcentage_r1 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r1).'%" />.' . round($pourcentage_r1) . "% </label><br />"; if ($infos['proposition2'] != "") echo $infos['proposition2'].'<br/>'. "<input type='radio' name='sondage' value='prop2' id='prop2' /> <label for='prop2'>" .'<img src="copper.jpg" height="10"width="' . $pourcentage_r2 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r2).'%" />.' . round($pourcentage_r2) . "% </label><br />"; if ($infos['proposition3'] != "") echo $infos['proposition3'].'<br/>'. "<input type='radio' name='sondage' value='prop3' id='prop3' /> <label for='prop3'>" .'<img src="copper.jpg" height="10"width="' . $pourcentage_r3 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r4).'%" />.' . round($pourcentage_r3) . "% </label><br />"; if ($infos['proposition4'] != "") echo $infos['proposition4'].'<br/>'. "<input type='radio' name='sondage' value='prop4' id='prop4' /> <label for='prop4'>" .'<img src="black.jpg" height="10"width="' . $pourcentage_r4 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r4).'%" />.' . round($pourcentage_r4) . "% </label><br />"; if ($infos['proposition5'] != "") echo $infos['proposition5'].'<br/>'. "<input type='radio' name='sondage' value='prop5' id='prop5' /> <label for='prop5'>" .'<img src="blue.jpg" height="10"width="' . $pourcentage_r5 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r5).'%" />.' . round($pourcentage_r5) . "% </label><br />"; exit; } //note importante : s'insere toujours dans un nouveau id// $sql = "INSERT INTO $table1 (ip) VALUES ('$ip') WHERE id="."'" . $numeroDuSondage['nbre_entrees'] . "'"; mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
As-tu modifier la base que je te l'ai indiqué ?
Si oui il faut que tu mettes mettes les deux champs dans ton INSERT et pas seulement l'ip.
merci pour la réponse,
j'ai ajouté la nouvelle table t_vote
voici le script qui ne marche pas avec moi:
comment faire? pleaseCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 //script pour ajouter les votes et ip $ip = $_SERVER['REMOTE_ADDR']; $prop = "prop"; $resultat = "resultats"; $fin = false; if(isset($_POST['sondage'])) { for($i = 1; $i <= 5 && !$fin; $i++) { if($_POST['sondage'] == $prop . $i) { $votes[$resultat . $i] ++; mysql_query("UPDATE sondage SET " . $resultat . $i ." = '" . $votes[$resultat . $i] . "' WHERE id = '" . $numeroDuSondage['nbre_entrees'] . "'") or die(mysql_error()); $fin = true; } } } $vote_ip = $_SERVER['REMOTE_ADDR']; $sondage_id = $numeroDuSondage; $sql = "INSERT INTO $table1 (sondage_id, vote_ip) VALUES ('$vote_ip, $sondage_id') WHERE sondage_id="."'" . $numeroDuSondage['nbre_entrees'] . "'"; mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
j'ai ajouté la nouvelle table t_vote.
voici le script pour insert:
ne marche pas, quel est le script pour recuperer id et inserer dans la table id et ip.Code:
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 //On prend l'id le plus grand $nombreEntrees = mysql_query("SELECT MAX(id) AS nbre_entrees FROM sondage") or die(mysql_error()); $numeroDuSondage = mysql_fetch_assoc($nombreEntrees); //On sélectionne la question et les choix $req="SELECT question, proposition1, proposition2, proposition3, proposition4, proposition5 FROM sondage WHERE id = '" . $numeroDuSondage['nbre_entrees'] . "' "; $MySQL_infos = mysql_query($req) or die(mysql_error()); $infos = mysql_fetch_array($MySQL_infos); //On sélectionne le nombre de votes $MySQL_votes = mysql_query("SELECT resultats1, resultats2, resultats3,resultats4,resultats5 FROM sondage WHERE id = '" . $numeroDuSondage['nbre_entrees'] . "'") or die(mysql_error()); $votes = mysql_fetch_assoc($MySQL_votes); //script pour ajouter les votes //script pour ajouter les votes et ip $ip = $_SERVER['REMOTE_ADDR']; $prop = "prop"; $resultat = "resultats"; $fin = false; if(isset($_POST['sondage'])) { for($i = 1; $i <= 5 && !$fin; $i++) { if($_POST['sondage'] == $prop . $i) { $votes[$resultat . $i] ++; mysql_query("UPDATE sondage SET " . $resultat . $i ." = '" . $votes[$resultat . $i] . "' WHERE id = '" . $numeroDuSondage['nbre_entrees'] . "'") or die(mysql_error()); $fin = true; } } } $vote_ip = $_SERVER['REMOTE_ADDR']; $sondage_id = $numeroDuSondage; $sql = "INSERT INTO $table1 (sondage_id, vote_ip) VALUES ('$vote_ip, $sondage_id') WHERE sondage_id="."'" . $numeroDuSondage['nbre_entrees'] . "'"; mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
merci
Tu n'as pas donné de valeur à la variable $vote_ip que tu as mis dans la requete.
$vote_ip = $_SERVER['REMOTE_ADDR'];
ca recupere adresse ip, ensuite dans insert.
comment faire d'autre, que faut-il mettre?
Ah oui tiens je l'avais raté.
Par contre enlève la condition WHERE.
ce qui me donne:
Erreur SQL !Code:
1
2
3
4
5 $vote_ip = $_SERVER['REMOTE_ADDR']; $sondage_id = $numeroDuSondage['nbre_entrees']; $sql = "INSERT INTO $table1 (sondage_id, vote_ip) VALUES ('$sondage_id, $vote_ip') "; mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
INSERT INTO t_vote (sondage_id, vote_ip) VALUES ('Array, 127.0.0.1')
Column count doesn't match value count at row 1
que faut-il faire?
merci