In this video (Part 33 of our Next.js + MySQL Job Portal App Series), you'll learn how to insert data into Employer and Applicant tables dynamically based on the user’s selected role during registration.
We’ll discuss: Why we created separate Applicant and Employer tables, What data needs to be inserted, And how to automatically save the user ID in the correct table depending on whether the user registered as an Applicant or an Employer. ---------------------------------------------------------------------------------- 📂 Source Code 👉 GitHub Repo: https://github.com/thapatechnical/job-portal-nextjs
⌛TIMELINE⏳ 0:00 Intro to inserting data in Applicant and Employer tables 0:25 Why we created separate Applicant and Employer tables 0:50 What data needs to be inserted in both tables 2:20 Pause the video & try it yourself 2:55 Support my channel ❤️ 3:28 How to find user role value after registration 4:50 Writing code to insert data in Applicant table 6:10 Inserting data in Employer table 6:45 Checking if data is successfully inserted in database 8:15 Next video update & closing notes
Hello, what's up guys. Welcome to your next session. MySQL present job portal application and today is our day number 33.
And today we are going to see that whenever someone is registering, I am adding that user's data to the user's table.
And on the basis of that, we create sessions for them so that they can auto log in.
And then if they visit our website within 30 days, we do not have to log in with them, they will be able to access automatically.
Protected routes, we have seen that.
Employees and then applicants, we have created their schema.
When we created this table, why did we create it? There must be some reason behind it.
And that reason is that when we were creating the schema, we saw that there is a one-to-one relationship between the two.
That is, whenever someone registers, he will definitely go to the user's table.
But we have one field that makes sure that the user is either an applicant or an employer.
So based on this role, what do we have to do?
If the user chooses a job applicant, then we have to add the same user details to the applicant table.
If the user selects an employer, then based on this role, we will add the details of that user to the employer's table.
You can see here that we have already added a user.
By the way, this is from my practice video, which you can't watch.
So I have already added one there.
And the data I have added is nothing but only the user ID.
Because with the help of user ID, I can easily find out what are the records of this employer in our user's table.
That is, who does it belong to?
Because if I look at 33, then I can see very clearly that here I am this user with 33.
You can see 33 here, right?
So I can very easily find out what is the name of that employer, what is his username and password.
So it's a very simple video, but it's just as useful.
So please, I would like you to pause the video now.
Use your own brain a little bit.
And think about it.
When we were registering, I obviously added the data to our user's field.
But based on this role, whether he is an applicant or an employer, I just have to add the records of the user's ID to these specific tables.
That's it.
If the user chooses an applicant from these two tables, then the user's ID will be stored in the applicant.
And if the user chooses an employer, then the employee's ID will be stored in this way.
You just have to write such a small insert query with the help of Drizzle.
So guys, please pause the video now and try it yourself.
Alright, I think at least you have tried it.
And many of you must have done it.
Awesome.
Before starting the video, if you haven't checked out the previous videos yet, then please do it.
It will help you a lot.
Because we are creating a full-stack project.
And if you like my efforts, if you like my videos, if you like my hard work.
So guys, please, if you want to support me in any way, I don't want anything.
Just subscribe to the channel.
I will be very happy.
Do like the video.
And if someone wants to join my community, then you can also join.
Okay?
Alright.
So I'll take you straight to my registration part.
Okay?
So the code you are seeing now is my registration page, which you can see on the UI.
Guys, you can see that we have used a server action where we have this register user action.
Okay?
This is our actual code.
In the backend, we are doing everything.
What is there?
What is not there?
Data validation has been done.
The most important thing here is this.
If you look closely.
So this is a line because of which I can say very confidently.
Yes, I know what the user has written in his name.
Yes, I know the user's username, password, and then what role the user has selected.
This is it.
This is this part where I have got the role that the user has either selected an applicant or an employer.
That's fine.
Whatever it is, what are we doing?
Does that user already exist?
Is that username already registered?
In such cases, we cannot register them.
We need a unique name from them.
And if everything goes well, then we insert it directly.
And if anything goes wrong, then we throw this error message.
And obviously, we have to hash the password.
So this is the password part.
So we have inserted the data in our user's table.
But this is not enough.
Now we have to insert it in the applicant and the employer's table.
How will we do it?
Look at my role.
If it is triple equal to applicant.
Here you can see the automatic suggestion.
This is it. Applicant.
So let me do one thing.
For now, I will remove the return.
Look simple.
And wait.
Write the spelling correctly.
db.
This is obviously a database.
.what
.insert
We have a method.
But in which table?
If the role of the user is applicant, then no doubt it will be your applicant table only.
And there are applicants.
Okay.
And remember one thing.
These are the applicants.
Yeah, this is it.
See.
I have got the applicant table from our drizzle schema.
This is very important.
You have to import that table.
So this is my job.
Now here it will not just be written insert.
We have values.
And what do you have to store in values?
What do you have to store?
We need to store only the ID.
Now how will I get this ID?
It is very easy.
So we have already seen.
We have this result.
And I had told you in a video.
Whenever you get data.
See.
Result.insertID
This is what I have to paste here.
This is it.
So basically in insertID, you get the actual ID of that user.
Now.
Else.
If he is not an applicant.
We are 110% sure that he is an employer.
Okay.
So here I am.
The employer table.
And you can see.
I hit enter.
So I also imported it.
ID.
And then insertID.
That's it.
Did you see?
Why did I tell you to pause and type it yourself?
Because.
It was so small.
How hard it was.
I had to write 4 lines.
For today's video.
But this is just as important.
Isn't it?
It has its own importance.
So yeah.
This is it.
That's all I had to do.
Now if I go here.
Okay.
I refresh it once.
And whatever details I have here.
I fill it.
So guys.
You can see.
I have filled all my details here.
I have only not filled a single detail.
And that is I am what?
Select your role.
So I do job applicant.
Because in my applicant table.
It is totally empty.
This is completely empty.
There is nothing in it.
So if I have selected applicant.
And I click on create account.
And boom guys.
You can see.
Registration completed successfully.
It has been redirected to our applicant's dashboard.
I go here.
Refresh it.
And boom guys.
See.
This is it.
You can see.
I have got 38.
Data has been added to my applicant table.
Let's go to users.
It is 38.
See.
38.
How did you like it?
Isn't it?
So awesome.
Finally.
Now a user.
Who we were studying since then.
The relation between them.
What is this?
What is that?
Isn't it?
If you remember.
See this.
What was the relation of a user with an employer?
Isn't it?
See this.
Now you know.
Why I have put users.id and employers.id on fields.
This is it.
A common between them.
Isn't it?
See this.
With the applicant.
Now I hope.
Now you know all these relations.
Because we have already seen all this.
Because now it is easy for us.
Isn't it?
So yeah guys.
This is it.
That's all for today's video.
I won't do for employers.
Because obviously.
My applicant is on my applicant.
So employers.
Coming to employers.
Is 110% confirmed.
Isn't it?
So yeah.
This is it.
That's all for today's video.
Now in tomorrow's video.
We will see.
How we can use transaction in this?
Yes guys.
In MySQL.
Transaction is very important.
So in tomorrow's video.
I will implement it.
And show you live.
How we can use it.
If you want.
You can try it yourself.
As a homework.
Where you can use transaction.
And from which region.
You can use it.
Here you will find many places.
Where you can use transaction.
Isn't it?
And if you want.
And if you have no idea.
About transaction.
Then you can check out my video.
Thapa Technical.
Transaction in MySQL.
Thapa Technical.
You will get it.
And rest.
If you like the video.
Then please like.
Share it with your friends.
And next target is.
8 lakh subscribers.
If you haven't subscribed yet.
Then please do it.
See you in next video.
Till then guys.
Thank you so much.
Take care.