what happens is that when inserting the data in the form some of the input we have to put it as type number so that it can be saved in the database and if it is saved, the probe is when we want to send them to call and edit the data that is as type number does not show only shows those that are in type text. and the ones that we keep with the input type number in the database have the structure that that field in the database is integer and double so how can I show it to them and edit them?
formular.html
<div ng-app="sa_app" ng-controller="controller" ng-init="show_data()">
<div class="col-md-6">
<input type="text" name="idproducto" id="idproducto" ng-model="idproducto" class="form-control" placeholder="ID Producto">
<br/>
<input type="text" name="producto" id="producto" ng-model= "producto" class="form-control" placeholder="Producto">
<br/>
<input type="text" name="descripcion" id="descripcion" ng-model="descripcion" class="form-control" placeholder="Descripcion">
<br/>
<input type="number" name="existencia" id="existencia" ng-model="existencia" class="form-control" placeholder="Existencia">
<br/>
<input type="number" name="preciocompra" id="preciocompra" ng-model="preciocompra" class="form-control" placeholder="Precio de compra">
<br/>
<input type="number" name="precioventa" id="precioventa" ng-model="precioventa" class="form-control" placeholder="Precio de venta">
<br/>
<input type="number" name="idproveedor" id="idproveedor" ng-model="idproveedor" class="form-control" placeholder="ID Proveedor">
<br/>
<input type="hidden" ng-model="idp">
<input type="submit" name="insert" class="btn btn-primary" ng-click="insert()" value="{{btnName}}">
</div>
</div>
inser.php
<?php
$conn = mysqli_connect("localhost", "root", "", "bdga");
$info = json_decode(file_get_contents("php://input"));
if (count($info) > 0) {
$idproducto = mysqli_real_escape_string($conn, $info->idproducto);
$producto = mysqli_real_escape_string($conn, $info->producto);
$descripcion = mysqli_real_escape_string($conn, $info->descripcion);
$existencia = mysqli_real_escape_string($conn, $info->existencia);
$preciocompra = mysqli_real_escape_string($conn, $info->preciocompra);
$precioventa = mysqli_real_escape_string($conn, $info->precioventa);
$idproveedor = mysqli_real_escape_string($conn, $info->idproveedor);
$btn_name = $info->btnName;
if ($btn_name == "Insert") {
$query = "INSERT INTO productos(idproducto,producto,descripcion,existencia,preciocompra,precioventa,idproveedor) VALUES ('$idproducto','$producto','$descripcion','$existencia','$preciocompra', '$precioventa', '$idproveedor')";
if (mysqli_query($conn, $query)) {
echo "Agregado con exito...";
} else {
echo 'Fallo';
}
}
if ($btn_name == 'Edit') {
$idp = $info->idp;
$query = "UPDATE productos SET idproducto = '$idproducto',producto = '$producto',descripcion = '$descripcion',existencia = '$existencia',preciocompra = '$preciocompra',precioventa = '$precioventa', idproveedor = '$idproveedor' WHERE idp = '$idp'";
if (mysqli_query($conn, $query)) {
echo 'Data Updated Successfully...';
} else {
echo 'Failed';
}
}
}
?>
script
<script>
var app = angular.module("sa_app", []);
app.controller("controller", function($scope, $http) {
$scope.btnName = "Insert";
$scope.insert = function() {
if ($scope.idproducto == null) {
alert("Ingresa el id del producto");
} else if ($scope.producto == null) {
alert("Ingresa Producto");
} else if ($scope.descripcion == null) {
alert("Ingresa descripcion");
} else if ($scope.existencia == null) {
alert("Ingresa existencia");
} else if ($scope.preciocompra == null) {
alert("Ingresa precio de compra");
} else if ($scope.precioventa == null) {
alert("Ingresa precio de venta");
} else if ($scope.idproveedor == null) {
alert("Ingresa id proveedor");
} else {
$http.post(
"insert.php", {
'idproducto': $scope.idproducto,
'producto': $scope.producto,
'descripcion': $scope.descripcion,
'existencia': $scope.existencia,
'preciocompra': $scope.preciocompra,
'precioventa': $scope.precioventa,
'idproveedor': $scope.idproveedor,
'btnName': $scope.btnName,
'idp': $scope.idp
}
).success(function(data) {
alert(data);
$scope.idproducto = null;
$scope.producto = null;
$scope.descripcion = null;
$scope.existencia = null;
$scope.preciocompra = null;
$scope.precioventa = null;
$scope.idproveedor = null;
$scope.btnName = "Insert";
$scope.show_data();
});
}
}
$scope.show_data = function() {
$http.get("display.php")
.success(function(data) {
$scope.names = data;
});
}
$scope.update_data = function(idp,idproducto,producto,descripcion,existencia,preciocompra,precioventa,idproveedor) {
$scope.idp = idp;
$scope.idproducto = idproducto;
$scope.producto = producto;
$scope.descripcion = descripcion;
$scope.existencia = existencia;
$scope.preciocompra = preciocompra;
$scope.precioventa = precioventa;
$scope.idproveedor = idproveedor;
$scope.btnName = "Update";
}
$scope.delete_data = function(idp) {
if (confirm("Seguro que deseas eliminar producto?")) {
$http.post("delete.php", {
'idp': idp
})
.success(function(data) {
alert(data);
$scope.show_data();
});
} else {
return false;
}
}
});
</script>
display.php
<?php
$conn = mysqli_connect("localhost", "root", "", "bdga");
$output = array();
$query = "SELECT * FROM productos";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
$output[] = $row;
}
echo json_encode($output);
}
?>