Issue inserting into 2nd table when using set value action

When I enable the set value step in my server action (reformatting email to lower case) my second table insert no longer works. Can someone put me in the right direction.

Thanks

What are your server action steps? And where do you apply the formatter exactly?
Are there errors when you debug your server action on submitting the form?

Here are my steps.

I will have to figure out how to debug

Well, it’s explained here:

As for your steps - why are you using a setvalue step there instead of directly formatting the value on insert?

Thanks for the debug.

Honestly I have no clue on why I am using the set value there instead of the doing the function on the insert.

Not that is wrong, but it’s an unnecessary additional step :slight_smile:

So ran the debug and I am getting an unauthorized error

the unauthorized probably comes from the login step at the end of your server action, maybe there’s something wrongly configured there. What’s the purpose of the login step at the end - to log in the user that just registered?
Is the data still not getting inserted properly?

I have the server action there to login in the user on registration and you are most likely correct that there is an issue there as I noticed my dynamic events at not working either which are hide modal and a success notification that the user is registered.

The data got inserted into the users table just fine but not in the roles table.

When I disabled the login step my dynamic events start working so that is good :slight_smile: baby steps

I do keep getting this error

  1. {status: “404”, message: “/api/security/user_loggedin? not found.”}

  2. message: “/api/security/user_loggedin? not found.”

  3. status: “404”

This means you link the server action called security/user_loggedin on the page which does not exist.

The error message says:

{status: “404”, message: “/api/security/user_loggedin? not found.”}

while your server action is located at /api/registration/user_loggedin so somewhere on the page you try to call the server action from the wrong location … check in your code where is it called exactly and fix/remove it.

Ok fixed the 404 error, I changed the name of my api folder to registration it started life in this project called security. I assumed when I renamed the folder it would update all of the code. Seems that is not the case which is a good lesson to learn this early in the game.

Now back to the data not being insert into my roles table, this is still not working.

It is odd because a new row is create whenever I register a new user however it is not inserting the entry for the column of user_id, it created a role_id and insert the role, which is hard coded to the letter M for any new registrations. Just need to figure out why it is not inserting the user_id into the roles table, this is a “foreign key” to the user_id in the users table.

Thanks so much for helping me get over this hump.

Sorry i am not following. You have 2 insert steps. Which one is working and which one not - how are both set up?

Yes that is correct 1 table is the users table insert and the other is a roles table insert

users table - inserting basic information about the user

roles table - inserting the user_id with a role set statically for now as M for a basic member of the site.

So what is not working for you now?

Can I just make sure you have the correct setup here:

I noticed you are inserting a user and then I assume this newly inserted user should be given roles?

The reason I ask is in your insert to the roles table you are looking for a POST variable named user_id which if this is going to the newly inserted user wouldn’t have been available in the form as it didn’t exist.

Instead to get the new users id you should be getting the identity from the insert step where you add the user.

1 Like

The issue I am having is that the user_id data is not being populated into the roles table in the user_id column.

Ok but what is $_POST.user_id? This expects a form input from your page to send this id. You don’t want to do that, you want to get the inserted identity from the previous insert step and use it there instead.

It seems you are attempting to use the POST.user_id, but I believe what you are looking for is the identity of the insert into the users table.