How do I get the data of several input that autocomplete to another

0

Good afternoon, I have this bbdd with 7 tables. link In the last one as we can see I have 4 PK because it is necessary to be able to have a document with the same name but with different versions.

The problem is:

How do I collect the data correctly to delete a row and not 20 rows at a time because it only recognizes a primary key?

I have this code

<?php
require_once 'alumno.entidad7.php';
require_once 'alumno.model7.php';
$alm = new Categoria();
$model = new CategoriaModel();
if (isset($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
case 'eliminar':
        $model->Eliminar = array(($_REQUEST['titulo_documento']['num_documento']['version']['revision']));

        header('Location: index7.php');
        break;
    }
}
?>

This would be the php part and this the html in the same file

<?php foreach ($model->Listar() as $r): ?>
                    <tr>
                        <td><?php echo $r->__GET('titulo_documento'); ?></td>
                        <td><?php echo $r->__GET('proyecto'); ?></td>
                        <td><?php echo $r->__GET('estado'); ?></td>
                        <td><?php echo $r->__GET('idioma'); ?></td>
                        <td><?php echo $r->__GET('num_documento'); ?></td>
                        <td><?php echo $r->__GET('version'); ?></td>
                        <td><?php echo $r->__GET('revision'); ?></td>
                        <td><?php echo $r->__GET('descripcion'); ?></td>
                        <td><?php echo $r->__GET('fecha'); ?></td>
                        <td><?php echo $r->__GET('subcategoria'); ?></td>
                        <td><?php echo $r->__GET('confidencialidad'); ?></td>
                        <td><?php echo $r->__GET('tipo_documento'); ?></td>
                        <td><?php echo $r->__GET('acro_usuario'); ?></td>
                        <td><?php echo $r->__GET('aprobado_por'); ?></td>
                        <td><?php echo $r->__GET('autorizado_por'); ?></td>
                        <td><?php echo $r->__GET('revisor'); ?></td>
                        <td><?php echo $r->__GET('compania'); ?></td>
                        <td><?php echo $r->__GET('codigo_proyecto'); ?></td>
                        <td>
                            <a href="?action=eliminar&titulo_documento=<?php echo $r->titulo_documento; ?>&num_documento=<?php echo $r->num_documento; ?>
                               &version=<?php echo $r->version; ?>&revision=<?php echo $r->revision; ?>"><img src="delete.png" width="30px" height="30px"/></a>
                        </td>
                    </tr>
                <?php endforeach; ?>

And in another file I would come to declare this another

public function Eliminar($categoria,$categoria1,$categoria2,$categoria3) {
    try {
        $stm = $this->pdo
                ->prepare("DELETE FROM documento WHERE titulo_documento = '?' and num_documento = ? and version = ? and revision = ?");


        $stm->execute(array($categoria,$categoria1,$categoria2,$categoria3));
    } catch (Exception $e) {
        die($e->getMessage());
    }
}

I also have problems updating, but first I want to be able to delete records and once someone can help me try to fix the part of the UPDATE. Many thanks to all who can help me

    
asked by Alberto Cepero de Andrés 05.04.2017 в 19:13
source

1 answer

0

On the line

$model->Eliminar = array(($_REQUEST['titulo_documento']
    ['num_documento']['version']['revision']));

You are assigning something to a function and trying to access a four-dimensional array that is not such. It should be:

$model->Eliminar($_REQUEST['titulo_documento'], $_REQUEST['num_documento'],
    $_REQUEST['version'], $_REQUEST['revision']);

My recommendation is that you save yourself headaches with so much field. Create a id_documento int PRIMARY KEY AUTOINCREMENT field in the table and then add a UNIQUE (titulo_documento, num_documento, version, revision) rule.

From there, use only the id of the document.

To generate the HTML:

<a href="?action=eliminar&id=<?php echo $r->id_documento; ?>"
    ><img src="delete.png" width="30px" height="30px"/></a>

To delete the record:

$stm = $this->pdo
            ->prepare("DELETE FROM documento WHERE id_documento = ?");
$stm->execute(array($id));

Much easier, right?

    
answered by 07.04.2017 в 01:20