bonjour j'ai un léger soucis lorsque j'essaie de faire un contrôle avant d'insérer une donnée dans ma base de donnée mysql . j'ai une erreur qui s'affiche(x3 avec ma boucle):
Warning: mysql_result() expects parameter 1 to be resource, string given in C:\wamp\www\mysql.php on line 84


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php
	$fp = fopen("test.xml","r"); //ouverture en lecture
	$xmlstr = "";
	while (!feof($fp)) { //on parcourt toutes les lignes
		$xmlstr .= fgets($fp, 4096); // lecture du contenu de la ligne
	}
 
	$xmlObject=new SimpleXMLElement($xmlstr);
 
	$db=mysql_connect("localhost", "root") or die("connection impossible");
	mysql_select_db("projet",$db) or die ("base non trouvé");
 
	class agent
{
public $matricule;
public $dateentree;
public $civilite;
public $nomusuel;
public $nompatronymique;
public $nommarital;
public $prenom;
}
$i=0;
 
 
		$result = $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="matricule"]/dsml:value');
		$result1= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="entree"]/dsml:value');			
		$result2= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="civilite"]/dsml:value');
		$result3= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="nomUsuel"]/dsml:value');
		$result4= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="nomPatronymique"]/dsml:value');
		$result5= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="nomMarital"]/dsml:value');
		$result6= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="prenom"]/dsml:value');
 
		foreach ($result as $title) {  
		$ag[$i]=new agent;
		$ag[$i]->matricule=$title;
		$i+=1;
		echo $title . "\n"; }
		$i=0;
		foreach ($result1 as $title1) { 
 
		$ag[$i]->dateentree=$title1;
		$i+=1;
		echo $title1 . "\n"; }
		$i=0;	
		foreach ($result2 as $title2) { 
 
		$ag[$i]->civilite=$title2;
		$i+=1;		
		echo $title2 . "\n";  }
		$i=0;
		foreach ($result3 as $title3) {  
		$ag[$i]->nomusuel=$title3;
		$i+=1;
		echo $title3 . "\n";  }
		$i=0;
		foreach ($result4 as $title4) {  
		$ag[$i]->nompatronymique=$title4;
		$i+=1;
		echo $title4 . "\n";  }
		$i=0;
		foreach ($result5 as $title5) {  
		$ag[$i]->nommarital=$title5;
		$i+=1;
		echo $title5 . "\n";  }
		$i=0;
		foreach ($result6 as $title6) {  
		$ag[$i]->prenom=$title6;
		$i+=1;
		echo $title6 . "\n";  }
		$i=0;
		for($i=0;$i < 3;$i++) 
		{
		$title=$ag[$i]->matricule;
		$title1=$ag[$i]->dateentree;
		$title2=$ag[$i]->civilite;
		$title3=$ag[$i]->nomusuel;
		$title4=$ag[$i]->nompatronymique;
		$title5=$ag[$i]->nommarital;
		$title6=$ag[$i]->prenom;
		$controle="select matricule 
		from agent
		where matricule=$title";
mysql_query($controle) or die("erreur sur la requete sql");
		$res=mysql_result($controle ,0);
		echo $res;
		if ($res=$title)
		{echo"enregistrement de ja present pour cet agent";
		}
		else{
		$sql="INSERT INTO AGENT (idagent,matricule,entree,civilite,nomUsuel,nomPatronymique,nomMarital,prenom)
		values('$i','$title','$title1','$title2','$title3','$title4','$title5','$title6')";
		mysql_query($sql) or die("erreur sur la requete sql");
		}
		}
 
 
 
	mysql_close($db);
	fclose($fp);
 
?>
Je recherche juste a se qu'il ni ait pas de doublon dans la base de donnée.Apparemment l'erreur viendrait du type de la valeur retournée mais je n'en suis pas sur et ne voit pas comment la résoudre .