FABRIK 3.0.6.3 not saving data in database table using PHP code

joezart

New Member
HI

Joomla 2.5
Fabrik 3.0.6.3
database type: Mysqli
default database connection id: 1
extra database call asam connection id: 2

Using the extra database I created a list from one of its table called "partidas" with an autoincremental number id.

In the same database (extra) I have another table called "estructuras" with the following fields

id ........................................an autoincremental number
partida_id ..............................id from partidas table
cargo ...................................1,2,3,4,5,6,7,8,9,

In this table (estruturas) I need to create 9 registers for every register created by the "partidas form"

let's say we are creating the 23rd register at partidas,
then table estructuras should look like this:

id........partida_id..........cargo
150..........23.....................1
151..........23.....................2
152..........23.....................3
153..........23.....................4
154..........23.....................5
155..........23.....................6
157..........23.....................7
158..........23.....................8
159..........23.....................9

In partidas form I have included the following PHP code, process script: "I try them all"

PHP:
 // To open a specific database using fabrik 3
  $db = FabrikWorker::getDbo(false, 2)
   
  //Return the last id of the table partidas
  $db->setQuery("SELECT MAX(id) FROM partidas");
  &partidas_last_id = $db->loadResult();
   
  for ($counter = 1; $counter <= 10; $counter += 1) {
          $db->setQuery("INSERT INTO estructuras (partida_id, cargo_id) VALUES ('$partidas_last_id', '$counter')");
          $db->query();
   
          // Debug sql sentence
          if (!$db->query()) {
                  var_dump($db->getErrorMsg());
                  var_dump($partida_id);
                  var_dump($cargo_id); 
                  exit;
          }
  }
I also try the following PHP code with all process script

PHP:
         //Variables for connecting to your database.
          //These variable values come from your hosting account.
          $hostname = "asam.db.xxxx.hostxx.com";
          $username = "wxw";
          $dbname = "asam";
   
          //Connecting to your database
          mysql_connect($hostname, $username, $password) OR DIE ("Unable to 
          connect to database! Please try again later.");
          mysql_select_db($dbname);
   
          //Return the last id of the table partidas  
          $query = "SELECT MAX(id) FROM partidas";
          &partidas_last_id = mysql_query($query);
          
          for ($counter = 1; $counter <= 10; $counter += 1) {      
                  // Insert a row of information into the table "estructura"
                  mysql_query("INSERT INTO estructuras (partida_id, cargo_id) VALUES ('$partidas_last_id', '$counter')") 
                  or die(mysql_error()); 
          }
I want to mention that according to the wiki

http://fabrikar.com/wiki/index.php/Form_plugin_php

PHP code to execute on from submission - If no script is selected then the code entered here will be run instead.
It is location in components/com_fabrik/plugins/form/fabrikphp
this file path do no exits in fabrik 3.0.6.3


RESULTS
Register at partidas database table created
NO registers created at estructuras database table

QUESTION
Why fabrik is not saving data into estructuras database table
according to PHP code?
 
in the first example you are running the query twice!
Code:
[COLOR=#000000][COLOR=#0000BB]$db[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]query[/COLOR][COLOR=#007700]();
   
          [/COLOR][COLOR=#FF8000]// Debug sql sentence
          [/COLOR][COLOR=#007700]if (![/COLOR][COLOR=#0000BB]$db[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]query[/COLOR][COLOR=#007700]()) {

try replacing that with just:

Code:
[/COLOR][/COLOR]
[COLOR=#000000][COLOR=#007700]if (![/COLOR][COLOR=#0000BB]$db[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]query[/COLOR][COLOR=#007700]()) {

have you tried putting and exit; at the end of the script so you can see the
generated errors?
Have you checked your server log?

[/COLOR][/COLOR]
Why fabrik is not saving data into estructuras database table
according to PHP code?

This is really a Joomla/PHP coding question and not Fabrik per see as far as I can see

 
I have try everything... using php file or adding code into the php box

1. Your sugested code DO NOT WORK
2. At the end of first example there is an exit. but never shows any generated error

Rob would mind taking a look into my site?
Can I sent you a private with access info

Remeber Im using a joomla 2.5.9 version
fabrik 3.0.6.3
and Mysqli database

thanks?
 
In both examples there's a typo
&partidas_last_id = $db->loadResult();
If your code has a php error it won't run at all, so doing no var_dump or exit;
 
Thanks Troester

From the time I posted this thread and your answer I try many options one of them was removing the "&" typo and results still the same.... NOT WORKING

Last code I try in the PHP box:
PHP:
// To open a specific database using fabrik 3
$db = FabrikWorker::getDbo(false, 2)

//Return the last id of the table partidas
//$ids = JRequest::getVar('rowid');
//$ids = JRequest::getVar('rowid', array());

//Return the last id of the table partidas
$db->setQuery("SELECT MAX('id')FROM partidas");
$ids = $db->loadResult();

for ($counter = 1; $counter <= 10; $counter += 1) {
    $db->setQuery("INSERT INTO estructuras (partida_id, cargo_id) VALUES ('$ids', '$counter')");
    $db->query();
exit;
}

Also this one didn't work
you can see several comment lines, the reason for place them into the code is for you to see some of the options I had tryed

Would you guys please get into my site and try to find out what the problem might be??

Thanks
 
Some more in your last code:
$db = FabrikWorker::getDbo(false, 2);
and
SELECT MAX('id') should be SELECT MAX(id) or MAX(`id`)

Try
...
$ids = $db->loadResult();
var_dump($ids);exit;

or compose line by line with dumping;exit;
to see where it stops working.
 
Thanks troester

Let's say we are half way

For the moment your code is saving data at "partidas" table (this has never been a problem)

At estructuras table save data, but do not execute the "FOR", so the table looks like this

id........partida_id..........cargo
150..........23.....................0

but what we need is this:
id........partida_id..........cargo
150..........23.....................1
151..........23.....................2
152..........23.....................3
153..........23.....................4
154..........23.....................5
155..........23.....................6
157..........23.....................7
158..........23.....................8
159..........23.....................9

now your code looks like this
PHP:
// To open a specific database using fabrik 3
$db = FabrikWorker::getDbo(false, 2);

//Return the last id of the table partidas
//$ids = JRequest::getVar('rowid');
//$ids = JRequest::getVar('rowid', array());

//Return the last id of the table partidas
$db->setQuery("SELECT MAX(`id`)FROM partidas");
$ids = $db->loadResult();
var_dump($ids);exit;

for ($counter = 1; $counter <= 10; $counter += 1) {
    $db->setQuery("INSERT INTO estructuras (partida_id, cargo_id) VALUES ('$ids', '$counter')");
    $db->query();
exit;
 
Troester Ignore my last post I just realized that I had some {} misssing

But I have 2 new situations

1.
table estructures looks like this

id........partida_id..........cargo
150..........23.....................0
150..........23.....................1
151..........23.....................2
152..........23.....................3
153..........23.....................4
154..........23.....................5
155..........23.....................6
157..........23.....................7
158..........23.....................8
159..........23.....................9


I need the records start with "1", like this
id........partida_id..........cargo
150..........23.....................1
151..........23.....................2

2.
When you click on the form partidas you got a white screen, what can I do to keep the same screen or moving to any I decide

Thanks
 
Sounds to me like you had error reporting turned off on your site.

Have you checked your server log?

Guess you didnt :) As all errors tend to be stored in the error log regardless of what is shown on the browser screen. If error reporting is turned off then errors are not reported on the screen, which leads us neatly to I think this:

When you click on the form partidas you got a white screen,
Sounds like a fatal error has occurred and that error reporting is turned off
Take a look at this wiki page regarding that:
http://fabrikar.com/forums/index.php?wiki/reporting-bugs/
specifically the 'I've got a whitescreen what next?' section.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top