Charly66 Charly66 - 6 months ago 21
SQL Question

Problems deleting a row with php

I'm trying to remove a row from a table with php. I have the following piece of code:

<?php
if($_GET["act"] == 'eliminarart' && $_GET["id"] != '')
{
var_dump($_GET);
if($mysql->query("DELETE FROM landing_articulos WHERE id_articulo = ". intval($_GET["id"])." LIMIT 1")){
redirige('nuevapagina.php');
} else {
$e=$mysqli->error;
echo $e;
}
}
?>

<head>
<script language="javascript">
function eliminar_art(id){
var mensaje = 'Deseas eliminar este articulo?';
eliminar = confirm(mensaje);
if (eliminar)
document.location='nuevapagina.php?act=eliminarart&id='+id;
}
</script>
</head>


I call all this code here:

while($f1 = mysql_fetch_array($c1)){
?>
<div style="float:left; width:32%; padding-left:0px; color:#ef5000; font-weight:bold; margin:5px;"><p><a href="http://www.certifacil.es/articulos/<?=$f1["url"]?>" target="_blank"><strong><?=$f1["nombre"];?></strong></a> <a href="editar_nuevapagina.php?id=<?=$f1["id_articulo"]?>"><img src="imagenes/lapiz.png" width="15" height="15" border="0"/></a> </a> <a href="javascript:eliminar_art('<?=$f1["id_articulo"]?>');"><img src="imagenes/delete.png" width="15" height="15" border="0"/></a> <? if($f1["valido"]=='0')echo ' - SIN VALIDAR';?></p></div><?
}


The
var_dump
returns data, although the id I get is a string instead of an int as it's defined in the database. So what I am doing wrong? All this code is in a page called
nuevapagina.php
.

Answer

no need to convert into integer just simply do it as:

$mysql->query("DELETE FROM landing_articulos WHERE id_articulo = ".$_GET["id"]." LIMIT 1"