Salut,
mon problème est comment inserer l'id d'un attribut dans une BD mysql.
J'ai essayé avec l'exemple ci dessous mais ça ne marche pas.
code htmlcode php
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 <html> <head> <script type="text/javascript" src="jquery.js"></script> <title>Insertion_Image_dans_BD</title> <script language="javascript"> $(document).ready(function(){ $("div table").find("img").each(function(){ $(this).click(function(){ var id=$(this).attr('id'); $.ajax({ type:"POST", url:"image.php", data:"id="+$("#id").val(), success:function(rep){ alert (rep); } }); return false; }); }); }); </script> </head> <body> <div align="center"> <form method="Post"> <table border="1" width="450"> <tr><td><input type="image" src="images/i1.png" id="t1" name="t1"/>1</td> <td><input type="image" src="images/i2.png" id="t2" name="t2"/>2</td> <td><input type="image" src="images/i3.png" id="t3" name="t3"/>3</td> </tr> <tr><td><input type="image" src="images/i4.png" id="t4" name="t4"/>4</td> <td><input type="image" src="images/i5.png" id="t5" name="t5"/>5</td> <td><input type="image" src="images/i6.png" id="t6" name="t6"/>6</td> </tr> </table> </form> </div> </body> </html>
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?php $id=$_POST["id"]; echo ($id); mysql_connect("localhost","root",""); mysql_select_db("pfe"); $res=mysql_query("insert into table(id) values('".$id."')"); if($res) { echo("Le dernier ID inséré dans est le %d\n", mysql_insert_id()); } ?>
merci d'avance.
Partager