Needing a little help to point me to the issue. I am building a component and need to insert a row into the Joomla DB.
This line works, but I have to create the table name myself and I'd rather use the built-in Joomla functions.
$config = JFactory::getConfig();
$dbprefix = $config->get('dbprefix');
$db_arr = array($dbprefix,'conquest_ctg_players');
$table_name = implode("",$db_arr);
$sql = "INSERT INTO $table_name (id, ordering, state, checked_out, checked_out_time, created_by, modified_by, player_name, player_uuid, player_bann, player_level, player_xp, player_gold, resource_food, resource_supplys, resource_population, quest_energy, troops_basic, troops_advanced, jid)
VALUES ('null', 1, '1', '0', '0000-00-00 00:00:00', '$userId', '$userId','$nUser', '$myuuid', '0', '1', '0', '50', '50', '50', '100', '100', '100', '0', '$userId')";
but this one errors out:
$sql
->insert($db->quoteName('#__conquest_ctg_players'))
->columns($db->quoteName('id', 'ordering', 'state', 'checked_out', 'checked_out_time', 'created_by', 'modified_by', 'player_name', 'player_uuid', 'player_bann', 'player_level', 'player_xp', 'player_gold', 'resource_food', 'resource_supplys', 'resource_population', 'quest_energy', 'troops_basic', 'troops_advanced', 'jid'))
->values(null, 1, 1, 0, $db->quote('0000-00-00 00:00:00'), $userId, $userId,$nUser, $myuuid,0, 1, 0, 50, 50, 50, 100, 100, 100, 0, $userId);
The error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AS
ordering
) VALUES ()' at line 2
This one will create a new table entry but does not have any values.
$sql
->insert($db->quoteName('#__conquest_ctg_players'))
->columns(id, ordering, state, checked_out, checked_out_time, created_by, modified_by, player_name, player_uuid, player_bann, player_level, player_xp, player_gold, resource_food, resource_supplys, resource_population, quest_energy, troops_basic, troops_advanced, jid)
->values('null', '1', '1', '0', '0000-00-00 00:00:00', '$userId', '$userId','$nUser', '$myuuid', '0', '1', '0', '50', '50', '50', '100', '100', '100', '0', '$userId');
If anyone can tell me why they think it is adding a row, but not inputting info, I would be eternally grateful.
[SOLVED]
in the title here. Please do not edit your pages in this manner. Awarding the green tick to the most helpful, resolving answer is the way to signify the resolution of a question.