Nueva pregunta

Pregunta:

Fecha: 30-05-2018 04:33:34 (En Español)

boton de borrar y editar en mi tabla en mi db[No resuelta]

buenas mi código funciona bien pero a la hora de borrar no puedo lograrlo . e visto demas de tutoriales y no logro como hacerlo. quiero hacerlo con un anchor tag para redirigir la página a otra donde borres o elimines el producto. pero no logro que mi delete.php funcione ni mi modificar.php tampoco. ya muestro en mi index la informacion que quiero y quiero borrarla de mi db. ayudadaaaaaa.gracias
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tabla de Pagos </title>
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" />
</head>
<body>
    <div class="container">
        <div class="page-header">
        <h1>Pagos de Clientes</a></h1>
        </div>
        <table class="table table-bordered table-condensed table-hover table-striped">
        <?php 
            $link = new PDO('mysql:host=localhost;dbname=radius', 'root', ''); // el campo vaciío es para la password.
        ?> 
		<thead>
        	 <tr>
				<th>Ticket</th>
				<th>Usuario</th>
				<th>Cedula</th>
				<th>Referencia</th>
				<th>Monto</th>
				<th>Estatus</th>
				<th>Aciones</th>
            </tr>
        </thead>
            
		<?php
        require_once ("dbconfig.php");
        session_start();
        // Establece los mensajes de sesion
        $_SESSION['message'] = "";
        //Valida si es enviado por post
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            if (isset($_POST['registro_pagos'])) { // aqui me introduce los datos en registro empleados
                require_once './app/registro_pagos.php'; //requiere de registro empleados
            } 
        }
    
        //Clase para manejar la conexion a la base de datos
            class Connect
            {
                private $user = "root";//usuario de mysqlk
                private $pass = "";//clave de mysql
                private $base = "radius";//base de datos en mysql
                private $server = "localhost";//servidor de alojamiento
                public  $error;//en caso de error se almacena aqui
                public  $db;
                public  function __construct(){
                    $mysqli = new mysqli($this->server, $this->user, $this->pass, $this->base);
                    if ($mysqli->connect_errno) {
                        $this->error = "Fallo al conectar a MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
                    }
                    $this->db = $mysqli;
                }
            }
            //Clase trabajo que se extiende de Connect
            class Trabajo extends Connect
            {
                public function __construct(){
                    parent::__construct();
                }
                public function valida($x){
                        $a = $this->db->query("SELECT * FROM archivos_pagos WHERE referencia = '$x' ");
                        
            $t = $a->num_rows;

                    if($t>=1){
                        //Si el cliente realizó el pago retorno la información
                        $row = $a->fetch_object();
                        return $row;
                    }else{
                        //si no retorno falso
                        return false;
                    }
                }

                public function data(){
                    $a = $this->db->query("SELECT * FROM pagos_pagina");
                    $con=1;
                    while($row = $a->fetch_object()){
                        //Envío a validar la referencia del cliente
                        $valida = $this->valida($row->referencia);
                        if($valida){                           
                echo "<tr>
                        <td>".$con."</td>
                        <td>".$row->nombre." ".$row->apellido."</td>
                        <td>".$row->cedula."</td>
                        <td>".$valida->referencia."</td>
                        <td>".$row->monto."</td>
                        <td> Pago Valido</td>
                        <td><a class='delete_product' data-id='<?php echo $id; ?>' href='javascript:void(0)'>
                            <i class='glyphicon glyphicon-trash'></i>
                            </a></td>
                            </tr>
                    </tr>";
            }else{
                echo"<tr>
                        <td>".$con."</td>
                        <td>".$row->nombre." ".$row->apellido."</td>
                        <td>".$row->cedula."</td>
                        <td>".$row->referencia."</td>
                        <td>".$row->monto."</td>
                        <td>Pago Invalido</td>
                        <td><a class='delete_product' data-id='<?php echo $valida; ?>' href='javascript:void(0)'>
                            <i class='glyphicon glyphicon-trash'></i>
                            </a></td>
                            </tr>     
                    </tr>";
                } 
                $con++;
            }
            echo "</table>";
            }
        }
        $p = new trabajo();
        $p->data();
    ?>
</table>
    </div>
<script src="jquery-1.12-0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="bootbox.min.js"></script>
<script>
	$(document).ready(function(){
		
		$('.delete_product').click(function(e){
			
			e.preventDefault();
			
			var pid = $(this).attr('data-id');
			var parent = $(this).parent("td").parent("tr");
			
			bootbox.dialog({
			  message: "Estas seguro que quieres borrarlo?",
			  title: "<i class='glyphicon glyphicon-trash'></i> Borrar !",
			  buttons: {
				success: {
				  label: "No",
				  className: "btn-success",
				  callback: function() {
					 $('.bootbox').modal('hide');
				  }
				},
            danger: {
                label: "Delete!",
                className: "btn-danger",
                callback: function() {
                    
                    /*
                    
                    using $.ajax();
                    
                    $.ajax({
                        
                        type: 'POST',
                        url: 'delete.php',
                        data: 'delete='+pid
                        
                    })
                    .done(function(response){
                        
                        bootbox.alert(response);
                        parent.fadeOut('slow');
                        
                    })
                    .fail(function(){
                        
                        bootbox.alert('Something Went Wrog ....');
                                                
                    })
                    */
                    
                    
                    $.post('delete.php', { 'delete':pid })
                    .done(function(response){
                        bootbox.alert(response);
                        parent.fadeOut('slow');
                    })
                    .fail(function(){
                        bootbox.alert('Algo fue Wrog ....');
                    }) 					  
				  }
				}
			  }
			});
		});
	});
</script>
</body>
</html>


conexion.php




dbconfig.php
<?php
	
	$DBhost = "localhost";
	$DBuser = "root";
	$DBpass = "";
	$DBname = "radius";
	try{
		
		$DBcon = new PDO("mysql:host=$DBhost;dbname=$DBname",$DBuser,$DBpass);
		$DBcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		
	}catch(PDOException $ex){
		
		die($ex->getMessage());
	}



delete.php
<?php
	require_once 'dbconfig.php';
	if ($_REQUEST['delete']) {
		
		$pid = $_REQUEST['delete'];
		$query = "DELETE FROM pagos_pagina WHERE id=:pid";
		$stmt = $DBcon->prepare( $query );
		$stmt->execute(array(':pid'=>$pid));
		
		if ($stmt) {
			echo "Producto eliminado con éxito ...";
		}
		
	}


tambien probé esto pero no funciona o no logro hacerlo funcionar.
<td><a href='editar.php?id=".$rows['id']."'> <button type='button' class='btn btn_danger'>Editar</button></a></td>
                                                        <td><a href='borrar.php?id=".$rows['id']."'> <button type='button' class='btn btn_danger'>Eliminar</button></a></td>


si este ejemplo se puede arreglar o si me pudieran mostrar otro ejemplo seria bien y muchas gracias de antemano.
Etiquetas: HTML - PHP Votos: 0 - Respuestas: 1 - Vistas: 12 Compartir en: Google Facebook Twitter LinkedIn Link
 

Respuestas:

  • Fecha: 17-06-2018 14:03:56 <td><a class='btn btn_danger' href='editar.php?id=".$rows['id']."'> Editar</a></td>
    <td><a class='btn btn_danger' href='borrar.php?id=".$rows['id']."'> Eliminar</a></td>
    prueba así amigo
      Votos: 0 - Link respuesta
     
Para participar activamente de la comunidad primero debes autenticarte, ingresa al sistema.Iniciar Sesión
 
frjcbbae garagebible.com