button to remove row from my db

0

my code works fine but I want to add buttons to delete and edit so I will start with eliminating but I do not achieve it and I have tried everything and nothing I need your help. index.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Pagos Listos</title>
    </head>
    <body>
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">Administradores Registrados</h1>
            </div>
            
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                  
                    
                    </div>
                        <?php 
                            $link = new PDO('mysql:host=localhost;dbname=radius', 'root', ''); // el campo vaciío es para la password.
                        ?> 
                        <div class="panel-body">
                            <form role="form" action="controller_login.php" method="post">
                                <table method="post" action="#" width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example" >
                                    <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 ("./conexion.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>Valido</td>
                                                        <td><a href='delete.php?nombre=". $id[0]."'>Eliminar</td>
                                                       
                                                        
                                                    </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 href='delete.php?pagos_pagina=". $id[0]."'>Eliminar</td>
                                                        <td></td>
                                                    </tr>";
                                                } 
                                                $con++;
                                            }
                                            echo "</table>";
                                            }
                                        }
                                        $p = new trabajo();
                                        $p->data();
                                    ?>
                                </table>
                            </form>    
                        </div>    
                    </div>    
                </div>               
            </div> 
        </div>
    </body>
</html>
connection.php

<?php 
	class Db{
		private static $conexion=null;
		private function __construct(){}

		public static function conectar(){
			$pdo_options[PDO::ATTR_ERRMODE]=PDO::ERRMODE_EXCEPTION;
			self::$conexion=new PDO('mysql:host=localhost;dbname=radius','root','',$pdo_options);
			return self::$conexion;
		}
	}
// aqui va unas linea de conexion extras y probar si la conexion existente funciona con mi ya arcgivo csv

$servername = "localhost";
$username = "root";
$password = "";
 //Create connection
$conn = new mysqli($servername, $username, $password);

 //Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
mysqli_select_db($conn,'radius'); // aqui en ves de poner (csvdata) pondre radius

?>

delete.php

<?php
 require_once ("conexion.php");
$id = $_GET['id'];
    $link = mysql_connect('localhost', 'root', '') or die('No se pudo conectar: ' . mysql_error());
mysql_select_db('pagos_pagina') or die('No se pudo seleccionar la base de datos');
$url = "";
$sql = "DELETE FROM pagos_pagina WHERE id = $id"; 

if (mysqli_query($link, $sql)) {
    mysqli_close($link);
    header('Location: mostrar.php');
    exit;
} else {
    echo "Error borrando al usuario";
}
?>

thanks

    
asked by alam 25.05.2018 в 17:28
source

0 answers