Adding Attribute Records To a New User

Advanced Questions & Problems

Adding Attribute Records To a New User

Postby JohnB » 6:52pm, Tue 02 Apr, 2013

When I add a new User manually within phpList it creates a record for each attribute in the php_user_attribute table, even if I have not entered any data for the attribute.

When a new user is added using the subscribe form, only attributes that are on the subscribe form are added to the php_user_attribute table. I've tried creating the missing attributes using a hidden field on the subscribe form, but it doesn't work, and searching the forum it looks as though other people have found this too.

The reason I'm asking is that I want to be able to update one of the attribute fields from another system, but that means that the attribute record needs to exist for every user. I've got it working how I want it where the records do exist.

It seems odd that the two methods of adding users are inconsistent. Is there any way to get round this problem within phpList?
phpList newbie
Posts: 4
Joined: 10:44am, Wed 02 Feb, 2011

Re: Adding Attribute Records To a New User

Postby JacobN » 8:20pm, Tue 02 Apr, 2013


When you're creating your subscribe page, it's only going to log to the php_user_user_attribute table it looks like the attributes that you've selected for that subscribe page.

It looks like it adds attributes in this fashion:

Code: Select all
<input type="text" name="attribute1" class="attributeinput" size="40" value="">

I think simply adding new hidden text fields isn't going to work, because it looks like in the php_subscribepage_data table it has entries for what you created on the subscription page. So you might be able to manually enter something in the database there along with a hidden text field on the subscription page to have it entered.

I can't see any other way to get it directly working without manual intervention which is a shame.

- Jacob
PL Nut
Posts: 33
Joined: 4:34pm, Tue 01 Jan, 2013

Re: Adding Attribute Records To a New User

Postby JohnB » 9:20pm, Tue 02 Apr, 2013

I've linked it to a contact management system I've written, so anyone who subscribes is automatically added to my system. I'm trying to automate as much as possible so it doesn't get complicated to run. My mySQL skills aren't good enough to work out how to write a query to add what I want to my system easily. I've thought of a way to do it, but think it could be rather slow, so I was hoping that phpList would do it.
phpList newbie
Posts: 4
Joined: 10:44am, Wed 02 Feb, 2011

Re: Adding Attribute Records To a New User

Postby duncanc » 2:47pm, Sat 06 Apr, 2013

At the risk of telling you something you know already, you can insert into or update the user_attribute table in one statement. Somethink like, but untested:

Code: Select all
insert into user_attribute
 (attributeid, userid, value)
values ($attr, $user, $value)
on duplicate key update value = $value

This will update the attribute value if the row exists otherwise insert a new row.

If you want to read the attribute value for a user, then a left join from the user table will ensure that you get a null value when the row does not exist. Something like this, and again untested:

Code: Select all
select ua.value
from user u
left join user_attribute ua on ua.userid = and ua.attributeid = $attribute
where = $user
Posts: 2440
Joined: 6:34am, Sat 08 May, 2010
Location: London

Return to Advanced Questions & Problems

Who is online

Users browsing this forum: No registered users and 2 guests