I made a mysql query that will copy 3 columns of data from one table to another:
INSERT INTO eio3k_hikers (link_id, link_name, user_id) SELECT link_id, link_name, user_id FROM eio3k_mt_links where eio3k_mt_links.link_id = (3)
I made a button which when clicked it should execute the query. My code looks like this:
<html>
<form action='' method='POST'>
<input type='submit' name='submit' />
</form>
</html>
<?php
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
// Get a db connection.
$db = JFactory::getDbo();
if(isset($_POST['submit'])){
// My query
$querySelect = $db->getQuery(true);
$querySelect->select('link_id, link_name, user_id');
$querySelect->from($db->quoteName('#__mt_links'));
$querySelect->where($db->quoteName('#__mt_links.link_id')." = ".$db->quote(3));
$queryInsert = $db->getQuery(true);
$queryInsert->insert($db->quoteName('#__hikers'));
$queryInsert->columns($db->quoteName(array('link_id, link_name, user_id')));
$queryInsert->values($querySelect);
$db->setQuery($queryInsert);
}
When I click on the button, the data does not insert. I also tried this in the last line:
$db->setQuery($queryInsert)->execute();
But then I got error:
1136 Column count doesn't match value count at row 1
although they are the same columns in both tables.