I have a list of data obtained from a database, but when I give "delete", in the text I get if I want to remove the product "id", and wanted to change that instead of the ID, leave the name of the product. The code that I have put is this:
<form autocomplete="on" method="post" name="delete_accesori" id="delete_accesori" action="index.php?page=controller_accesori&op=delete&id=<?php echo $_GET['id']; ?>">
<table border='0'>
<tr>
<td align="center" colspan="2"><h3>¿Desea seguro borrar el producto <?php echo $_GET['id'] ; ?>?</h3></td>
</tr>
<tr>
<td align="center"><button type="submit" class="Button_green"name="delete" id="delete">Aceptar</button></td>
<td align="center"><a class="Button_red" href="index.php?page=controller_accesori&op=list">Cancelar</a></td>
</tr>
</table>
</form>
and if instead of putting $ _GET ['id'], I put $ _GET ['accesori'] I do not get that field ... Any suggestions? Thanks in advance !!
EDITED: At the request of the user "Marcos" I add the code where the product information is printed:
<h1>Informació del producte</h1>
<p>
<table border='2'>
<tr>
<td>Accesori: </td>
<td>
<?php
echo $accesori['accesori'];
?>
</td>
</tr>
<tr>
<td>Imatge de l'accesori: </td>
<td>
<img src=" <?php
echo $accesori['imatge_accesori'];
?> ">
</td>
</tr>
<tr>
<td>Email: </td>
<td>
<?php
echo $accesori['email'];
?>
</td>
</tr>
<tr>
<td>Còdic del producte: </td>
<td>
<?php
echo $accesori['codprod'];
?>
</td>
</tr>
<tr>
<td>Marca: </td>
<td>
<?php
echo $accesori['marca'];
?>
</td>
</tr>
<tr>
<td>Modelo: </td>
<td>
<?php
echo $accesori['modelo'];
?>
</td>
</tr>
<tr>
<td>Cantitat: </td>
<td>
<?php
echo $accesori['cantitat'];
?>
</td>
</tr>
<tr>
<td>Fecha de stock: </td>
<td>
<?php
echo $accesori['data1'];
?>
</td>
</tr>
<tr>
<td>Fecha d'inici de l'oferta: </td>
<td>
<?php
echo $accesori['data2'];
?>
</td>
</tr>
<tr>
<td>Pais: </td>
<td>
<?php
echo $accesori['pais'];
?>
</td>
</tr>
<tr>
<td>Idioma: </td>
<td>
<?php
echo $accesori['idioma'];
?>
</td>
</tr>
<tr>
<td>Observaciones: </td>
<td>
<?php
echo $accesori['observaciones'];
?>
</td>
</tr>
<tr>
<td>Valoració: </td>
<td>
<?php
echo $accesori['valoracio'];
?>
</td>
</tr>
</table>
</p>
<p><a href="index.php?page=controller_accesori&op=list">Volver</a></p>
I also want to comment that I have already tried to do the <?php echo accesori['accesori'];?>
in the delete so that the name of the accessory comes out, but it does not work.
EDIT:
The function to remove the accessory is this:
function delete_accesori($accesori){
$sql = "DELETE FROM producte WHERE id='$accesori'";
/* print_r($sql);
die();*/
$conexion = connect::con();
$res = mysqli_query($conexion, $sql);
connect::close($conexion);
return $res;
}
The function to insert products in the database is this:
function insert_accesori($datos){
$id=$datos[id];
$accesori=$datos[accesori];
$imatge_accesori=$datos[imatge_accesori];
$email=$datos[email];
$codprod=$datos[codprod];
$marca=$datos[marca];
$modelo=$datos[modelo];
$cantitat=$datos[cantitat];
// $valoracio=$datos[valoracio];
$data1=$datos[data1];
$data2=$datos[data2];
$pais=$datos[pais];
foreach ($datos[idioma] as $indice) {
$idioma=$idioma."$indice/";
}
$observaciones=$datos[observaciones];
foreach ($datos[valoracio] as $indice) {
$valoracio=$valoracio."$indice/";
}
$conexion = connect::con();
$compro_cod = "SELECT * FROM producte WHERE codprod = '$codprod'";
$existe = mysqli_query($conexion,$compro_cod);
if (mysqli_num_rows($existe) > 0){
print_r('Error: Ya existe ese codigo <br/> <a href="index.php?page=controller_accesori&op=list">Volver</a>');
die();
} else{
$sql = " INSERT INTO producte (id, accesori, imatge_accesori, email, codprod, marca, modelo, cantitat, data1, data2, pais, idioma, observaciones, valoracio)"
. " VALUES ('$id','$accesori', '$imatge_accesori', '$email', '$codprod', '$marca', '$modelo', '$cantitat', '$data1', '$data2', '$pais', '$idioma', '$observaciones', '$valoracio')";
$res = mysqli_query($conexion, $sql);
connect::close($conexion);
return $res;
}
}
In that code I also check that the product code can not be repeated.
This is the part of the code that leads to the option to delete the product:
case 'delete';
if (isset($_POST['delete'])){
try{
$daoaccesori = new DAOAccesori();
$rdo = $daoaccesori->delete_accesori($_GET['id']);
}catch (Exception $e){
$callback = 'index.php?page=503';
die('<script>window.location.href="'.$callback .'";</script>');
}
if($rdo){
echo '<script language="javascript">alert("Borrado en la base de datos correctamente")</script>';
$callback = 'index.php?page=controller_accesori&op=list';
die('<script>window.location.href="'.$callback .'";</script>');
}else{
$callback = 'index.php?page=503';
die('<script>window.location.href="'.$callback .'";</script>');
}
}
include("module/accesori/view/delete_accesori.php");
break;