Announcement

#1 2011-04-18 18:17:40

Mattias
Translation Team
The Netherlands
2011-01-31
18

pwg_query

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:

Code:

<form method="post" name="some_name" action="path/dosomething.php" class="properties">

And dosomething.php contains something like this:

Code:

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"

Code:

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

 

#2 2011-04-19 11:08:03

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: pwg_query

Hi Mattias,

What does your dosomething.php contains?

Any file directly called from the web browser needs to start with:

Code:

define('PHPWG_ROOT_PATH','./');

(or '../', it all depends on where your dosomething.php file is)

Offline

 

#3 2011-04-26 21:11:27

Mattias
Translation Team
The Netherlands
2011-01-31
18

Re: pwg_query

At the moment it contains this...

Code:

<?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

 

#4 2011-04-27 14:10:03

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: pwg_query

wrong constant definition, better use this one:

Code:

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 :

Code:

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

 

#5 2011-04-30 16:47:58

Mattias
Translation Team
The Netherlands
2011-01-31
18

Re: pwg_query

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

 

#6 2011-05-02 14:57:36

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: pwg_query

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

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact