Hi
Im trying to create a simple plugin, but it wont let me run a query on the database.
What i tried is to run a php script after a user clicks the submit button.
Like this:
<form method="post" name="some_name" action="path/dosomething.php" class="properties">
And dosomething.php contains something like this:
echo "test 1"; $query='some hardcoded query here'; pwg_query($query); echo "test 2";
But it doenst update the database.
Also, it displays "test 1", but not "test 2"
Now i searched some further, and when i simply paste these lines inside my admin.php, it does work (it keeps firing the query over and over again :) )
After some more trying, i added this piece of code in top of the script, and it echo's "accidental hacking attempt"
if( !defined("PHPWG_ROOT_PATH") ) { echo "accidental hacking attempt"; }
So, the problem is not that pwg_query doesnt work, but that i use it wrong.
I just dont know how to use it right; in other plugins they do something with brackets (smarty?), but i dont know how that works...
Could anyone help?
Offline
Hi Mattias,
What does your dosomething.php contains?
Any file directly called from the web browser needs to start with:
define('PHPWG_ROOT_PATH','./');
(or '../', it all depends on where your dosomething.php file is)
Offline
At the moment it contains this...
<?php // "Any file directly called from the web browser needs to start with:" define('PHPWG_ROOT_PATH','../'); print('Start<br />'); // Get the data $foto_id = $_POST["foto_ids"]; $value1 = $_POST["value1"]; $value2 = $_POST["value2"]; print('Halfway<br />'); // Put it in the table $query = ' INSERT INTO extra_test_table (foto_id, value1, value2) VALUES (0, "2", "4") ON DUPLICATE KEY UPDATE value1="1", value2="2" ;'; $result = pwg_query($query); // this doesnt works print('Done!'); ?>
And the output is Start<br />Halfway<br />
Edit: This file is in the directory:
ftp://watergallery.nl/www/fotogallery/p … luginname/
Last edited by Mattias (2011-04-26 21:15:06)
Offline
wrong constant definition, better use this one:
define('PHPWG_ROOT_PATH', '../../');
But to use pwg_query and perform queries on the database, you need a database connection and many other things. The simpler to have a "ready to use" environment is to include include/common.inc.php right after :
define('PHPWG_ROOT_PATH', '../../'); include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
Note: it is not very common to use a plugin file directly. Most of the time, the plugin files are included by core files, this is why you don't have to define PHPWG_ROOT_PATH.
Offline
Ok thanks alot, it works now!
Note: it is not very common to use a plugin file directly. Most of the time, the plugin files are included by core files, this is why you don't have to define PHPWG_ROOT_PATH.
It might be a good idea to find out how to do it in admin.php itself i guess
Offline
Mattias wrote:
It might be a good idea to find out how to do it in admin.php itself i guess
Of course it would be better. Just take another plugin as model. Take [extension by plg] Community for instance, there is an administration screen with a form.
Offline