1
Does anyone know how to select a die and go to an editing screen, using html, Angularjs and php?
Example: I have a list of contacts. I want to make a button that saves the id of this contact and when I click, this button, it takes me to another html page where I can edit the data of this contact.
I have it:
<a href="editar.html?id={{usuario.id}}" class="btn btn-xs btn-primary">Editar</a>
And it works. I’m directed to edit.html and with the id in the url:
localhost:8888/systems/systems_web/Cadastro_angularjs/edit.html? id=1
On this page I have the following code:
<script type="text/javascript">
angular.module("myCrud", []);
angular.module("myCrud").controller("myCrudCtrl", function ($scope, $http) {
var carregarUsuario = function () {
$http.get("php/buscaPEdicao.php", {params: {id: usuario}}).success(function (data){
console.log(data);
$scope.usuarios = data;
});
};
carregarUsuario();
});
</script>
</head>
<body ng-controller="myCrudCtrl">
<div class="jumbotron">
<table class="table">
<tr>
<td>Nome</td>
<td>Email</td>
<td>Password</td>
</tr>
<tr ng-repeat="usuario in usuarios">
<td><input type="text" ng-model="usuario.newName">{{usuario.name}}</td>
<td><input type="text" ng-model="usuario.newEmail">{{usuario.email}}</td>
<td><input type="text" ng-model="usuario.newPass">{{usuario.pass}}</td>
</tr>
</table>
</div>
And my php:
<?php
$id = $_POST['id'];
$usuario = mysqli_query($con, "SELECT * FROM users WHERE id='$id'");
header('Content-Type: application/json');
$return = array();
while ($dados = mysqli_fetch_assoc($usuario)) {
array_push($return, $dados);
}
echo json_encode($return);
?>
Have some code to add to the question?
– rray
Not @rray... I just made the button with link to the page I will create.
– GustavoSevero
The problem is
$_GET['id']
is never set?– rray
@rray, first I took the exclamation mark and it didn’t work. .
– GustavoSevero
As you can see @rray, I changed $_GET['id'] to $_POST['id'] and I ran a test by Postman and the id is set.
– GustavoSevero
You are calling the method carry without passing the parameter user.
– Daniel
@Daniel, actually what I did is wrong, no parameter is passed.
– GustavoSevero
But where does the user of
{id: usuario}
?– Daniel
Yes, I saw some videos and there are people who put id as parameter. Mas and then? Because I put user as parameter and nothing changes. You are familiar with angular @Daniel?
– GustavoSevero
Friend let me see if I understand, you are having difficulty searching the user information when making the request for 'php/buscaPEdicao.php' ?
– Meeeefiu
Exactly @Mathdesigner47.
– GustavoSevero
But whatever your question, try to be more specific, at what points are you having difficulty?
– Meeeefiu
I understand yes, I will put an answer here.
– Daniel
@Mathdesigner47, is the following: I have a screen, in html, where I register contacts. On this same screen I have a button with link to another html file where I have to search from the database, only the data of the selected contact, I pass the id by the link button. However, I am not able to make the data, this contact, appear in this other page in html, understand? If you still don’t understand, write to [email protected], or access my git with the https://github.com/GugaSevero/CRUD_AngularJSfiles
– GustavoSevero
@Gustavosevero now I understand, I will write an answer.
– Meeeefiu