1
eric235u
xoopsDB & Error number: 0
  • 2007/4/13 17:14

  • eric235u

  • Not too shy to talk

  • Posts: 149

  • Since: 2004/12/19


hi all. newbie php questions here. i have a basic understanding of how to use xoopsDB. I'm currently trying to write a script to clean up my database and i'm getting the error,

Quote:
DELETE * FROM xpstestsite_xps_torrents WHERE TIMEDIFF(NOW(), xpstestsite_xps_torrents.last_scrape) >= '0000-00-02 00:00:00'
Error number: 0
Error message: Database update not allowed during processing of a GET request


i have the following on my index.php page,

Quote:
include(XOOPS_ROOT_PATH.'/modules/xpstorrent/clean.php');


and this is what clean.php looks like,

Quote:

/*
* xpsTorrent! - a bittorrent tracker module for XOOPS
* by eric235u
*
* clean.php
*/

require('../../mainfile.php');
global $xoopsDB;

// if scrape fails for 2 days DELETE
$table = $xoopsDB->prefix('xps_torrents');
$result = $xoopsDB->query("DELETE * FROM $table
WHERE TIMEDIFF(NOW(), $table.last_scrape) >= '0000-00-02 00:00:00'");

?>


so i guess my question is, how the heck do i execute this query? is it not proper to do it as an include or am i just using xoopsDB incorrectly?

thanks for any tips.

2
JCDunnart
Re: xoopsDB & Error number: 0
  • 2007/4/16 8:30

  • JCDunnart

  • Not too shy to talk

  • Posts: 114

  • Since: 2006/7/1 5


$xoopsDB->query( $sql ) will only execute:
1. when the sql statement is a 'select' statement or
2. when the insert/update/delete statement is coming from a $_POST request.

This is for security, so that $_GET requests are only able to 'view' data, not perform updates on the database.

To make your code work you need to either call the script using a POST request, or force the update by using $xoopsDB->queryF( $sql ). It's your choice which to use.

If you want to convert a GET request to POST you can use the confirmation page. This page is submitted as a POST request, which then allows the sql statement to be executed.

e.g.
if ( isset( $_POST['ok'] ) ) {
    
// execute your sql 
} else {
    
xoops_confirm( array( 'ok' => ), 'index.php'CONFIRM_TEXT );
}


If you don't want user interaction then use queryF.

Login

Who's Online

325 user(s) are online (259 user(s) are browsing Support Forums)


Members: 0


Guests: 325


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits