execute php to save a form.

afacuse

New Member
I am trying to execute php code when a form is saved.
To do this, in supplements form, add a php complement.

Paste the following code,
$ db = & JFactory :: getDBO ();
$ db-> setQuery ("INSERT INTO` ultima_inscripcion `(` test `)
VALUES ('test from form') ");

Neither one got to do print_r

If you want to run a php to save the form, the steps are well am I doing?
 

Attachments

  • Sin título-3.jpg
    Sin título-3.jpg
    61.1 KB · Views: 214
Thank you very much, followed suit, but does not work, I think q is not executing php. no way to tell if you run the php?

in columns try both ways
$ columns = array ('ultima_inscripcion___prueba');
$ columns = array ('prueba');
 
Ok, there was a $db->quote missing in the WIKI and at least on my site it's only working without try/catch (showing a system message if there's a SQL error).
This should do
Code:
// Get a db connection.
$db = JFactory::getDbo();
 
// Create a new query object.
$query = $db->getQuery(true);
 
// Insert columns.
$columns = array('prueba');
 
// Insert values.
$values = array('test from form');
 
// Prepare the insert query.
$query
    ->insert($db->quoteName('ultima_inscripcion')
    ->columns($db->quoteName($columns))
    ->values(implode(',', $db->quote($values)));
 
// Reset the query using our newly populated query object.
$db->setQuery($query);
 
// Execute the query
  $result = $db->execute();
 
Still not working with the code you sent me.

The table is well written and the field exists in the database.
the tests did from the back end, but the configuration is to be Realize from the zone administrator.
 

Attachments

  • fabrik.jpg
    fabrik.jpg
    62.4 KB · Views: 205
So a new record is inserted but prueba is NULL? i.e. the INSERT is working?
Or is no record inserted at all?

Is ultima_inscripcion a table created by fabrik? If not, what is the primary key?
What is the column type of prueba (in the database), which fabrik element plugin?
Can you post a screenshot of your code?
 
No, no record is inserted, which you see on the image with id = 3, is inserted from phpmyadmin to test if the query worked before show me the code.

the element type of "prueba" is field
ultima_inscripcion is created by fabrik
 
Before executing the query, dump it out, so you can se if the query is correct. So put this:

var_dump($query);exit;

... on the line before the execute(), which should just print out the query object to your browser. Copy and paste that output here.

-- hugh
 
add var_dump ($ query); exit; ejectuar before and nothing happens, I think the code is not running, but do not know how to check.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top