Copy to another table by PHP plugin

keianrad

Member
I tried to copy a record to another table but I don't know what should I put instead values. I used this code but it just copied the same words in values:

Code:
// Get a db connection.
$myDb = JFactory::getDbo();

// Create a new query object.
$myQuery = $myDb->getQuery(true);

// Insert columns.
$columns = array('name','date_time');

// Insert values.
$values = array('app_clients___name','app_clients___date_time');


// Prepare the insert query.
$myQuery
    ->insert($myDb->quoteName('app_customers'))
    ->columns($myDb->quoteName($columns))
    ->values(implode(',', $myDb->quote($values)));

// Reset the query using our newly populated query object.
$myDb->setQuery($myQuery);

try {
// Execute the query
  $result = $myDb->execute();
//use $myDb->query() in Joomla2.5
}
catch (Exception $e) {
// catch any database errors.

}
$newid = (int)$myDb->insertid(); //get new record id
 
I tried this code also but it doesn't work yet!!!
Code:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->insert('app_customers')
->set('date_time = ' . $myDb->quote('{app_clients___date_time}'))
->set('name = ' . $myDb->quote('{app_clients___name}'));
$myDb->setQuery($myQuery);
$myDb->execute();
$myId = $myDb->insertid();
 
Actually, I worked on it more than 5 hours and I got really tired of everything. all the time an error has occurred.
 
Last edited:
We are always happy to do tasks like this for you, on an hourly rate. We try an do as much as we can within a subscription, but obviously writing custom code can never be an "all you can eat" proposition.

Which form is this on? I assumed it would be on app_clients from the code, but I don't see any PHP plugins on that form.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top