I have this code that insert user and user group map in my database. But this doesn't work.
What's wrong with this:
What's wrong with this:
<?php
$db = &JFactory::getDBO();
$query =
" INSERT INTO prefix_users (id,name,username,email,password) VALUES ('{$form->data['id']}','{$form->data['name']}','{$form->data['username']}','{$form->data['email']}','{$form->data['password']}'), INSERT INTO prefix_user_usergroup_map (user_id,group_id) VALUES ('{$form->data['id']}',6)";
$db->setQuery($query);
$db->query();
?>
Hi tiagopc,
Which version of Joomla! is this?
And is the table prefix really 'prefix' ?
Bob
Which version of Joomla! is this?
And is the table prefix really 'prefix' ?
Bob
this is the latest version of joomla, and my prefix table is not "prefix" is just an exemple.
Hi tiagopc,
For Joomla! 3 please use $db->execute() instead of $db->query()
Bob
For Joomla! 3 please use $db->execute() instead of $db->query()
Bob
What i want to do is two inserts in the same custom code, code i'm doing is below:
This code is working, but i want to insert in this table at the same time:
Can you help me?
<?php
$db = &JFactory::getDBO();
$idaux = $form->data['id'];
$query = "INSERT INTO table_users (id, name) VALUES ('{$form->data['id']}, {$form->data['name']}');
er_usergroup_map (user_id,group_id) VALUES ('{$form->data['id']}',6)";
$db->setQuery($query);
$db->query();
?>
This code is working, but i want to insert in this table at the same time:
INSERT INTO table_user_usergroup_map (user_id,group_id) VALUES ('{$form->data['id']}',6)"
Can you help me?
The second insert is:
The intention is to get the user id that i've registrated and associate it with the group id '6'. Is that clear?
And thanks a lot for the help, Bob!
INSERT INTO eweb_user_usergroup_map (user_id,group_id) VALUES ('{$form->data['id']}',6)"
The intention is to get the user id that i've registrated and associate it with the group id '6'. Is that clear?
And thanks a lot for the help, Bob!
Hi tiagopc,
Sorry, I meant that you should just add a second query to the PHP.
BUT you probably should not write directly to the Joomla! User tables. There are JUser methods you can use to do make these changes. You should certainly NEVER write a password like this.
Bob
Sorry, I meant that you should just add a second query to the PHP.
<?php
$db = &JFactory::getDBO();
$query =
" INSERT INTO prefix_users (id,name,username,email,password) VALUES ('{$form->data['id']}','{$form->data['name']}','{$form->data['username']}','{$form->data['email']}','{$form->data['password']}')";
$db->setQuery($query);
$db->execute();
$query =
" INSERT INTO prefix_user_usergroup_map (user_id,group_id) VALUES ('{$form->data['id']}',6)";
$db->setQuery($query);
$db->execute();
?>
BUT you probably should not write directly to the Joomla! User tables. There are JUser methods you can use to do make these changes. You should certainly NEVER write a password like this.
Bob
Hi tiagopc,
Because Joomla! doesn't save the password in plain text. It saves a 'hash' that can be used to check the password but not to recover it.
Bob
Because Joomla! doesn't save the password in plain text. It saves a 'hash' that can be used to check the password but not to recover it.
Bob
This topic is locked and no more replies can be posted.