add a new drupal user

3 replies [Last post]
netzverdienst
Offline
Last seen: 6 years 15 weeks ago
Joined: 2012-12-06

hello,

i'd like to add a new user. i want to get some post data in a custom module and write them into the {users} table.
i come from php coding and i'm not very familiar with the special drupal coding yet.

here comes my code:

function catch_post_data() {

if ($_REQUEST['custfullname'] != NULL && $_REQUEST['custemail'] != NULL) {

$name = $_REQUEST['custfullname'];
$mail = $_REQUEST['custemail'];

//write data into the test data table
db_query("INSERT INTO {test} (tid, name, mail) VALUES ('', '$name', '$mail')");

// Generate a random password
$pass = random_pwd(8);

// Insert user into users table
db_query("INSERT INTO {users} (uid, name, pass, mail, status) VALUES ('', '$name', '$pass', '$mail', '1')");

}
}

writing the data into the {test} table works great but not into the {users} table!
do i have to implement a kind of user hook before i can write into the {users} table?

thanks for your help,
martin

frostmar
Offline
Last seen: 3 years 23 weeks ago
Joined: 2011-06-11
Don't do it!

Don't write to the users table. Create another table, preferable in the format _users and join to it on uid. Otherwise, you may experience problems when doing upgrades. You said it worked OK in your test table so simply select a proper name for the table.

Hope this Helps.

Martin.

frostmar
Offline
Last seen: 3 years 23 weeks ago
Joined: 2011-06-11
Sorry I did not read you properly the first time.

There is a function called user_save() which can be found here.

It all looks a bit daunting but if you search for "Posted by drippydrop" you'll find a good example of how to use it.

netzverdienst
Offline
Last seen: 6 years 15 weeks ago
Joined: 2012-12-06
thank's i'll test it martin

thank's i'll test it

martin

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.