I have a view where the data of the clients are displayed from a table'clientttente ', displayed by a ng-repeat suffers from an array, and for each line that belongs to each client I have an 'add' button, this button must add each client to another table 'client', when I try this code, it generates this error: undefined property "code", Where is the error please!
register.html
<div class="padding" ng-controller="RegisterCtrl" ng-init="loadClient1()">
<a class="button button-info" href="#/ajoutClient" style="background-color:#6EB4DC;float:right">Ajouter un client</a>
<table>
<tr>
<th>Code.Client</th>
<th>Nom</th>
<th>Prenom</th>
<td>Ajouter</td>
</tr>
<tr ng-repeat="x in names">
<td ng-model="code">{{x.CodeClient}} </a> </td>
<td ng-model="nom">{{x.NomClient}} </td>
<td ng-model="prenom">{{x.PrenomClient}}</td> >
<td><a class="button button-info" ng-click="insertClient()" >Ajouter</a> </td>
</tr>
</table>
app.js
$scope.insertClient = function(){
if(confirm("Êtes-vous sûr?"))
{
$http.post(
"http://localhost/deb/insertClient.php",
{
'code' :$scope.code,
'nom' :$scope.nom,
'prenom' :$scope.prenom,
}
).success(function(data){
});
}
else
{
return false;
}
}
insertClient.php
<?php
$connect = mysqli_connect("localhost", "root", "", "test");
$data = json_decode(file_get_contents("php://input"));
if(count($data) > 0)
{ $CodeClient=mysqli_real_escape_string($connect,$data->code);
$NomClient = mysqli_real_escape_string($connect, $data->nom);
$PrenomClient = mysqli_real_escape_string($connect, $data->prenom);
$query = "INSERT INTO client (NomClient,PrenomClient) VALUES
('$NomClient','$PrenomClient') WHERE CodeClient='$CodeClient'";
if(mysqli_query($connect, $query))
{
echo "The client has been successfully added";
}
else
{
echo 'Error';
}
}
?>
mysqli_real_escape_stringto prevent SQL injection