xoops forums

cmagana

Not too shy to talk
Posted on: 2003/12/29 8:21
cmagana
cmagana (Show more)
Not too shy to talk
Posts: 131
Since: 2003/11/8
#1

Help me, Problem with query DELETE FROM

Hello, I'm developing a module, but I have a problem, when I try to delete a record from certain table, my script doesn't delete the item, all the others work well: redirect and don't and it does not appear message of error.
The script is the next:

Quote:

<?php
require_once('../../../mainfile.php');
include_once(XOOPS_ROOT_PATH."/class/xoopsmodule.php");
include(XOOPS_ROOT_PATH."/include/cp_functions.php");
if ( $xoopsUser ) {
$xoopsModule = XoopsModule::getByDirname("cartelera");
if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
redirect_header(XOOPS_URL."/",3,_NOPERM);
exit();
}
} else {
redirect_header(XOOPS_URL."/",3,_NOPERM);
exit();
}
xoops_cp_header();

//Code to delete the item
$sql = sprintf("DELETE FROM %s WHERE id_horario = %s", $xoopsDB->prefix("cartelera_cat"), $_GET['horario']);
$xoopsDB->query($sql);
redirect_header("horarios.php",2,"Item deleted");

//Include the page footer
xoops_cp_footer();
?>


Please tell me where is my error, or what's bad??

tywick

Just popping in
Posted on: 2003/12/29 8:41
tywick
tywick (Show more)
Just popping in
Posts: 12
Since: 2002/9/17
#2

Re: Help me, Problem with query DELETE FROM

It would probably work better if you actually did a mysql_query instead of sprintf. I'm sure there's other changes you'd need to do but that's a good place to start.

robekras

Documentation Writer
Posted on: 2003/12/29 8:43
robekras
robekras (Show more)
Documentation Writer
Posts: 187
Since: 2002/12/10
#3

Re: Help me, Problem with query DELETE FROM

Maybe the following thread could help you

https://xoops.org/modules/newbb/viewto ... 23&forum=7#forumpost60438


cmagana

Not too shy to talk
Posted on: 2003/12/29 8:54
cmagana
cmagana (Show more)
Not too shy to talk
Posts: 131
Since: 2003/11/8
#4

Re: Help me, Problem with query DELETE FROM

Thanks for your fast help, I only changed this
$xoopsDB->query($sql); for $xoopsDB->queryF($sql);

Thanks and happy new year 2004, greetings from Mexico

Mithrandir

XOOPS is my life!
Posted on: 2003/12/29 11:29
Mithrandir
Mithrandir (Show more)
XOOPS is my life!
Posts: 6320
Since: 2003/6/21
#5

Re: Help me, Problem with query DELETE FROM

As always when using queryF be aware how the parameter is treated and security checks before executing the code, e.g. a permissions check prior to the $xoopsDB->queryF($sql); so not just anybody can do it once they know the url for the page.