Jump to content

Recommended Posts

Hi, 

 

I am having troubles trying to add View/Edit/Del options to my web system modules. I am not the creator of the web system so it's complicated for me, also, I am a newbie on this. 

I want to be able to view/edit/del from admin panel every product or client stored in my db. 

Here's the Clients module code:

 

client.html

 



<div ng-include="'views/menu.html'">
</div>
<button type="button" class="btn btn-primary" ng-model = 'newProduct' ng-click = 'newProductButton()'>{{buttonName}}</button>
<hr>
<div class="table-responsive" ng-show ='!newProduct'>
<table class="table table-striped table-hover">
<tr>
<td>Nº</td>
<td>Cédula</td>
<td>Nombre</td>
<td>Apellido</td>
<td>Dirección</td>
<td>Email</td>
<td>Télefono</td>
</tr>
<tr ng-repeat= 'client in clients track by $index'>
<td>{{$index + 1}}</td>
<td>{{client.codigo}}</td>
<td>{{client.nombre}}</td>
<td>{{client.apellido}}</td>
<td>{{client.direccion}}</td>
<td>{{client.email}}</td>
<td>{{client.telefono}}</td>
</tr>
</table>
</div>
<div ng-show = 'newProduct'>
<form role="form" ng-submit ="updateClient (id,name,lastName,address,phoneNumber,email)">
<label>Cédula</label>
<div class="form-group">
    <input class="form-control" placeholder="Cédula" ng-model='id' id="id">
  </div>
  <label>Nombre</label>
  <div class="form-group">
    <input class="form-control" placeholder="Nombre" ng-model='name' id="sname">
  </div>
  <label>Apellido</label>
  <div class="form-group">
    <input class="form-control" placeholder="Apellido" ng-model='lastName' id="lastName">
  </div>
  <label>Dirección</label>
  <div class="form-group">
    <input class="form-control" placeholder="Dirección" ng-model='address' id="address">
  </div>
  <label>Teléfono</label>
  <div class="form-group">
    <input type='tel' class="form-control" placeholder="Teléfono" ng-model='phoneNumber' id="phoneNumber">
  </div>
  <label>Email</label>
  <div class="form-group">
    <input type='email'class="form-control" placeholder="Email" ng-model='email' id="email">
  </div>
      <div class="alert alert-success" id='alertSuccess' style="display:none">Ingresado Satisfactoriamente...</div>
      <div class="alert alert-danger" id='alertDanger' style="display:none">Ese cliente ya fue agregado</div>
  <button type="submit" class="btn btn-primary">Agregar Cliente</button>
  </form>
</div>


 

client.js



'use strict';


/**
 * @ngdoc function
 * @name belkitaerpApp.controller:ClientCtrl
 * @description
 * # ClientCtrl
 * Controller of the belkitaerpApp
 */
angular.module('belkitaerpApp')
  .controller('ClientCtrl', function ($scope,$http) {
    $scope.newProduct = false;
  if($scope.newProduct){
  $scope.buttonName = 'Ver Tabla';
  }
  else{
  $scope.buttonName = 'Ingresar Cliente';
  }
  $http.get('../serverSide/clients.php').success(function(clients){
  console.log(clients);
  $scope.clients = clients.Clients;
  })
  $scope.newProductButton  = function(){
  $scope.newProduct = !$scope.newProduct;
  if($scope.newProduct){
  $scope.buttonName = 'Ver Tabla';
  }
  else{
  $scope.buttonName = 'Ingresar Cliente';
  }
  }
    $scope.updateClient = function(id,name,lastName,address,phoneNumber,email){
      $http.post('../serverSide/updateClient.php',{id:id,name:name,lastName:lastName,address:address,phoneNumber:phoneNumber,email:email}).success(function(data){
        console.log(data);
        $('#alertSuccess').show("slow");
          setTimeout(function() {
            $('#alertSuccess').hide('slow');
          }, 3000);
      }).error(function(data){
        console.log(data);
        $('<div id="alertDanger"></div>').show("slow");
          setTimeout(function() {
            $('<div id="alertDanger"></div>').hide('slow');
          }, 3000);
      })
    }
  });


 

client.php

 



<?php
require_once 'database.php';
$db = new Database();
$clients = $db->queryAll('SELECT clie_id as id,clie_cod as codigo, clie_ape as apellido, clie_nom as nombre, clie_dir as direccion, clie_ema as email, clie_tel as telefono FROM cliente','Clients');
echo json_encode($clients);
?>


 

I have found a php code on the web and I was wondering if it was possible to merge it with my existing one. I tested the code with my db and it's working but I do not know how to merge it with my existing code. 

Here's the code:

 



<?php
if (isset($_POST['submit']))
{   
include 'db.php';


$clie_cod=$_POST['clie_cod'] ;
$clie_ape= $_POST['clie_ape'] ;
$clie_nom=$_POST['clie_nom'] ;
$clie_dir=$_POST['clie_dir'] ;


mysql_query("INSERT INTO `cliente`(Código,Apellido,Nombre,Dirección) 
VALUES ('$clie_cod','$clie_ape','$clie_nom','$clie_dir')"); 




       }
?>
</form>
<table border="1">


<?php
include("db.php");




$result=mysql_query("SELECT * FROM cliente");


while($test = mysql_fetch_array($result))
{
$id = $test['clie_id'];
echo "<tr align='center'>";
echo"<td><font color='black'>" .$test['clie_id']."</font></td>";
echo"<td><font color='black'>" .$test['clie_cod']."</font></td>";
echo"<td><font color='black'>". $test['clie_ape']. "</font></td>";
echo"<td><font color='black'>". $test['clie_nom']. "</font></td>";
echo"<td><font color='black'>". $test['clie_dir']. "</font></td>";
echo"<td> <a href ='view.php?clie_id=$id'>Edit</a>";
echo"<td> <a href ='del.php?clie_id=$id'><center>Delete</center></a>";


echo "</tr>";
}
mysql_close($conn);
?>
</table>


</body>
</html>


 

Any help would be highly appreciated. Thank you very much.

Link to comment
https://forums.phpfreaks.com/topic/289872-help-with-vieweditdel-options/
Share on other sites

There is not going to be an easy way to just drop in some code to make this happen. Before you even start you need to fully understand your database schema. Otherwise, you run the risk of creating orphaned records that could be benign or could create real problems. For example, if you were to delete a client - that client may have placed order or had other records associated with them. What should happen to that associated data when the client is "deleted". If you delete the client and the associated data, then you lose all history of that associated data as well. For example, if you were to run an order history report it would be wrong. Also, if any inventory is based on order history the inventory would be wrong.

 

Or, if you delete the client and not the associated data, how would it be used? If you ran an order history report you could still have a problem where the orders are not reported depending on how the query is built. Or, if it is included, what should display in those reports where the client is included in the output.

 

Way, way too many issues you need to understand and plan for before creating any processes for deleting records. You will likely find that some records can be permanently deleted, while some can be "soft" deleted and other cannot be deleted at all.

 

 

Here is an example of one possible scenario:

 

Let's say you have a value for "Region" that is applied to clients. If any clients are assigned to a region AND region is a required value, then you can allow a region to be deleted if no clients are assigned to it. Or, during the delete operation, you could give the option to reassign any clients to a new region. If region is not required, then you can probably just allow any to be deleted without any checks - but you need to update the existing clients that reference the region to an appropriate Nu// or Default value.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.