j'ai réaliser un code en JS mais j'ai une erreur
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
 
// Replace these parameters to match your database
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'Mm101010';
$dbname = 'smartphone';
$table  = 'vu_affet_empl';
 
// Connect
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
 
// If parameters are received
if(isset($_POST['x']) && isset($_POST['y'])){
 
    $error_messages = array();
 
    if ($mysqli->connect_errno) {
        $error_messages[] = "Couldn't connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }
 
    // Prepare insert
    if (!($stmt = $mysqli->prepare("INSERT INTO `$table` (x,y) VALUES (?,?)"))) {
        $error_messages[] = "Couldn't prepare statement: (" . $mysqli->errno . ") " . $mysqli->error;
    }
 
    // Bind parameters x and y
    if (!$stmt->bind_param("dd", $_POST['x'], $_POST['y'])) {
        $error_messages[] = "Couldn't bind parameters: (" . $stmt->errno . ") " . $stmt->error;
    }
 
    // Execute the insert
    if (!$stmt->execute()) {
        $error_messages[] = "Couldn't execute the query: (" . $stmt->errno . ") " . $stmt->error;
    }
 
    // Prepare some data to return to the client (browser)
    $result = array(
        'success' => count($error_messages) == 0,
        'messages' => $error_messages
    );
 
    $stmt->close();
 
    // Send it
    echo json_encode($result);
    // Exit (do not execute the code below this line)
    exit();
 
} // end if
 
 
// Fetch all the coordinates to display them in the page
$res = $mysqli->query("SELECT * FROM `$table`");
$rows = array();
while ($row = $res->fetch_array()) {
    $rows[] = $row;
}
 
$mysqli->close();
?>
 
 
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Test page</title>
    <style>
    table{ border-collapse: collapse; }
    th,td{ border: 1px solid #888; padding: .3em 2em; }
    </style>
</head>
<body>
    <h1>New coordinates</h1>
    <table id="coordinates">
        <tr>
                <td>&nbsp;</td>
                <th>USER ID</th>
                <th>Nom</th>
                <th>Prenom</th>
                <th>Num SIM</th>
                <th>PIN Terminal</th>
                <th>PIN SIM</th>
                <th>Num EMEI</th>
                <th>Date Debut</th>
                <th>Date Fin</th>
                <th>Vitre</th>
                <th>Coque</th>
                <th>Support Vehicule</th>
                <th>Actif</th>
                <th>Or Affectation1</th>
                <th>Statut</th>
        </tr>
<?php
 
if(count($rows)){
    foreach($rows as $row){
?>
        <tr>
                <td><input type="radio" name="select" class="del_customer" value="<?php echo $row["USER_ID"]; ?>" /></td>
                <td><? $row["USER_ID"]?></td>
                <td><? $row["Nom"]?></td>
                <td><? $row["Prenom"]?></td>
                <td><? $row["Num_SIM"]?></td>
                <td><? $row["PIN_Terminal"]?></td>
                <td><? $row["PIN_SIM"]?></td>
                <td><? $row["Num_IMEI"]?></td>
                <td><? $row["Date_Debut"]?></td>
                <td><? $row["Date_Fin"]?></td>
                <td><? $row["Vitre"]?></td>
                <td><? $row["Coque"]?></td>
                <td><? $row["Support_Vehicule"]?></td>
                <td><? $row["Actif"]?></td>
                <td><? $row["Or_Affectation1"]?></td>
                <td><? $row["Statut"]?></td>
        </tr>
<?php
    }
}
 
?>
    </table>
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
        $(function(){
            $('#addBtn').click(postCoordinates);
 
            function postCoordinates(){
                var USER_ID = $('#USER_ID').val(),
                    Nom = $('#Nom').val(),
                    Prenom = $('#Prenom').val(),
                    Num_SIM = $('#Num_SIM').val(),
                    PIN_Terminal = $('PIN_Terminal').val(),
                    PIN_SIM = $('#PIN_SIM').val(),
                    Num_IMEI = $('#Num_IMEI').val(),
                    Date_Debut = $('#Date_Debut').val(),
                    Date_Fin = $('#Date_Fin').val(),
                    Vitre = $('#Vitre').val(),
                    Coque = $('#Coque').val(),
                    Support_Vehicule = $('#Support_Vehicule').val(),
                    Actif = $('#Actif').val(),
                    Or_Affectation1 = $('#Or_Affectation1').val(),
                    Statut = $('#Statut').val();
 
                if(x.length && y.length){
                    // Change this if it is on a different page
                    var url = window.location.href;
                    $.ajax({
                        'url': url,
                        'method': 'post',
                        'data': {'USER_ID': USER_ID, 'Nom': Nom, 'Prenom': Prenom, 'Num_SIM': Num_SIM, 'PIN_Terminal': PIN_Terminal, 'PIN_SIM': PIN_SIM, 'Num_IMEI': Num_IMEI, 'Date_Debut': Date_Debut, 'Date_Fin': Date_Fin, 'Vitre': Vitre, 'Coque': Coque, 'Support_Vehicule': Support_Vehicule, 'Actif': Actif, 'Or_Affectation1': Or_Affectation1, 'Statut': Statut},
                        'dataType': 'json', // The server will return json
                        'success': function(res){
                            if(res.hasOwnProperty('success') && res.success){
                                $('#USER_ID, #Nom, #Prenom, #Num_SIM, #PIN_Terminal, #PIN_SIM, #Num_IMEI, #Date_Debut, #Date_Fin, #Vitre, #Coque, #Support_Vehicule, #Actif, #Or_Affectation1, #Statut').val(''); // Empty the inputs
                                $('#coordinates').append('<tr><td>'+USER_ID+'</td><td>'+Nom+'</td></tr><tr><td>'+Num_SIM+'</td><td>'+PIN_Terminal+'</td></tr><tr><td>'+PIN_SIM+'</td><td>'+Num_IMEI+'</td></tr><tr><td>'+Date_Debut+'</td><td>'+Date_Fin+'</td></tr><tr><td>'+Vitre+'</td><td>'+Coque+'</td></tr><tr><td>'+Support_Vehicule+'</td><td>'+Actif+'</td></tr><tr><td>'+Or_Affectation1+'</td><td>'+Statut+'</td></tr>');
                            } else if(res.hasOwnProperty('messages')) {
                                alert( res.messages.join('\n') );
                            }
                        },
                        'error': function(x, s, e){
                            alert( 'Error\n' + s + '\n' + e );
                        }
                    });
                } else {
                    alert('You need to provide x and y coordinates');
                }
            }
        });
    </script>
 
</body>
</html>
Nom : Capture5NG.PNG
Affichages : 297
Taille : 13,4 Ko
je voudrais affiché un tableau depuis une base de donnée
merci