How to add users to a Joomla installation? Topic is solved

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
TheGardener

How to add users to a Joomla installation?

Post by TheGardener » Sun Dec 09, 2007 2:24 am

Hello,

Does anyone know how I can add users to a Joomla installation via PHP script? I've tried a script that adds new users by updating three tables like so:

Code: Select all


global $database;

# Set the register date

	$registerdate = date("Y-m-d H:i:s");

# Figure out what the last table id and determine the next one as $new_id

	$query = "SELECT MAX(id) FROM jos_users";

	

	$database->setQuery( $query );

	

	$old_id = $database->loadResult();

	

	$new_id = $old_id + 1;

# Figure out what the last table id and determine the next one as $new_aro_id



	$query_aro = "SELECT MAX(aro_id) FROM jos_core_acl_aro";



	$database->setQuery( $query_aro );

	

	$old_aro_id = $database->loadResult();

	

	$new_aro_id = $old_aro_id + 1;

# MD5 the Password as $encpassword



	$encpassword = md5($_POST['jos_users___password']);
	
	$query = "SELECT COUNT(username) from jos_users WHERE `username` = " .$_POST['jos_users___username']. "";

	

	$database->setQuery( $query );


	if ($database->getErrorNum()) {

		print("<font color=red>SQL error in jos_users in dupcheck" .$database->stderr(true). "</font><br />");

		return;

	}

		$dupCount = $database->loadResult();

		#echo "<br>For $username the count is $dupCount <br>";

	

	if ($dupCount > 0) {

	

		echo "Username Already Exists: " .$_POST['jos_users___username']. "<br>";

	

	} else {
		
		$query = "INSERT INTO jos_users VALUES (id, name, username, email, password , usertype, block, sendEmail, gid, registerDate, lastvisitDate) ('" .$new_id. "', '" .$_POST['jos_users___name']. "', '" .$_POST['jos_users___username']. "', '" .$_POST['jos_users___email']. "', '" .$encpassword. "', 'registered', '0', '0', '18', '" .$registerdate. "', '0000-00-00 00:00:00')";

		
		$database->setQuery( $query );

		

		$database->query();

		
		
		$query = "INSERT INTO jos_core_acl_aro (aro_id , section_value , value , order_value , name , hidden) VALUES ('" .$new_aro_id. "', 'users', '" .$new_id. "', '0', '" .$_POST['jos_users___name']. "', '0')";

		echo "INSERT INTO jos_core_acl_aro VALUES ('" .$new_aro_id. "', 'users', '" .$new_id. "', '0', '" .$_POST['jos_users___name']. "', '0')";

		$database->setQuery( $query );

		

		$database->query();


		$query = "INSERT INTO jos_core_acl_groups_aro_map VALUES (25, '', 10)";

		$database->setQuery( $query );

		

		$database->query();
	
	}

But this doesn't work. I've also tried the method posted here by Fennopolpot:

http://forum.joomla.org/index.php/topic ... msg1060307

But it doesn't work either. I'm using Joomla 1.0.13, whereas the post linked above specifies Joomla 1.5, so that may be the cause. The new user entries I create are showing up in the jos_users table and other tables like they're supposed to, but they still don't show up in the user list. Does anyone know the correct way to add a user? Thanks for any help you can provide.

Opie
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Thu Jun 22, 2006 7:32 pm
Contact:

Re: How to add users to a Joomla installation?

Post by Opie » Sun Dec 09, 2007 6:17 am

bascherz mentions a few more tables in regards to adding new users.
http://springhillalumni.org • Springhill High School Alumni Association


Post Reply