1
whereray
Can't insert PM
  • 2005/6/18 4:04

  • whereray

  • Just popping in

  • Posts: 29

  • Since: 2003/4/16


I write a test page to insert PM manually. But every time
when it executes privmessage.insert(&$pm)

!$result = $this->db->query($sql)

The $result is always empty and no row updated. following is test.php and debug code in privmessage.php
-----------------------------------------
<?php//test.php
require('header.php');

// Include the page header
include(XOOPS_ROOT_PATH.'/header.php');
$pm_handler =& xoops_gethandler('privmessage');
$pm =& $pm_handler->create();
$pm->setVar("subject", "New App");
$pm->setVar("msg_text", "New Text");
$pm->setVar("to_userid", "1");
$pm->setVar("from_userid", "1");
if (!$pm_handler->insert($pm)) {
echo $pm->getHtmlErrors();
echo "failed";
} else {
echo "done";
}

?>
-----------------------------------
<?php
// $Id: privmessage.php,v 1.3 2003/03/27 14:52:15
function insert(&$pm)
{
......//code neglected
if (!$result = $this->db->query($sql)) {
echo "Bad SQL:<br>$sql<br>";
echo "Result:$result!";
return false;
}
echo "Good SQL:\n$sql";
if (empty($msg_id)) {
$msg_id = $this->db->getInsertId();
}
$pm->assignVar('msg_id', $msg_id);
return true;
}

?>
----------------------------------------
//the printouts when using test.php

Bad SQL:
INSERT INTO xoops_priv_msgs (msg_id, msg_image, subject, from_userid, to_userid, msg_time, msg_text, read_msg) VALUES (0, 'icon1.gif', 'New App', 1, 1, 1119064960, 'New Text', 0)
Result:!

//the printouts when using PM module
Good SQL:
INSERT INTO xoops_priv_msgs (msg_id, msg_image, subject, from_userid, to_userid, msg_time, msg_text, read_msg) VALUES (0, 'icon1.gif', 'test1', 1, 1, 1119063876, 'test text', 0)

---------------------------------------


Why is this happening?? Can anybody help? How can I get a READABLE DB error msg? Many thanks!

2
whereray
Re: Can't insert PM
  • 2005/6/18 4:05

  • whereray

  • Just popping in

  • Posts: 29

  • Since: 2003/4/16



3
Mithrandir
Re: Cant insert PM

In order to update database information, you need to use a POST request (i.e. submit a form with method="post").

Alternatively - and only for the sake of testing - you could pass a second parameter to the $pm_handler->insert() method so it reads
$pm_handler->insert($pm, true);

This will force the query no matter the request method, but should only be used where absolutely necessary.

4
whereray
Re: Cant insert PM
  • 2005/6/18 16:00

  • whereray

  • Just popping in

  • Posts: 29

  • Since: 2003/4/16


$pm_handler->insert($pm, true)

still returns blank. And it makes no sense to force user use post to insert a pm into table.

Could Mithrandir show me how to do more? Sorry, i am a newbie.

5
Mithrandir
Re: Cant insert PM

<?php//test.php
require('header.php');

// Check caching and build blocks
include(XOOPS_ROOT_PATH.'/header.php');

//if form not submitted
if (!isset($_POST['submit'])) {
    echo 
"<form action='test.php' method='post'><input type='submit' name='submit' value='Press This' /></form>";
    exit();
}

$pm_handler =& xoops_gethandler('privmessage');
$pm =& $pm_handler->create();
$pm->setVar("subject""New App");
$pm->setVar("msg_text""New Text");
$pm->setVar("to_userid""1");
$pm->setVar("from_userid""1");
if (!
$pm_handler->insert($pm)) {
echo 
$pm->getHtmlErrors();
echo 
"failed";
} else {
echo 
"done";
}

?>

6
whereray
Re: Cant insert PM
  • 2005/6/20 2:33

  • whereray

  • Just popping in

  • Posts: 29

  • Since: 2003/4/16


it works, thanks!!!

Login

Who's Online

239 user(s) are online (163 user(s) are browsing Support Forums)


Members: 0


Guests: 239


more...

Donat-O-Meter

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

Latest GitHub Commits