我正在尝试使用php从表中删除一行。我有以下代码:
<?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>
我在这里调用所有这些代码:
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><?
}
var_dump
返回数据,虽然我得到的id是字符串而不是数据库中定义的int。那么我做错了什么?所有这些代码都在一个名为nuevapagina.php
的页面中。
答案 0 :(得分:0)
无需转换为整数,只需将其作为:
$mysql->query("DELETE FROM landing_articulos WHERE id_articulo = ".$_GET["id"]." LIMIT 1"