Skip to content
Advertisement

Create a table for each user with their ID

I have a problem with a website that I am currently creating that I need a table for each user but it does not work. I have tried to create a table during registration or the first login, which also works. My problem is with the naming of the table, because I want the table to have the following name. “user_1” The “user” is fixed and the number should be the ID of the user. This is how it should look like, the table user works without problems, but the other tables do not work.

DB currently:

  • users
  • user_

DB desired content:

  • users
  • user_1
  • user_2

Table users:

JavaScript

My previous opportunities: So far I have tried to create the table if the registration was successful. Here was the error that I could create the table, but it created it under the name “user_”. The “id” was simply left out and so I can create a table.

With my second approach I tried to store a “False” value in the table during registration and check during login if the value is “False”, if so then change this value to “True” and create the table. But here I had the same problem as with my first attempt that the id was not given to me.

My code: registration.php:

JavaScript

createPersonalTable.php:

JavaScript

I think the main problem is reading the ID (i.e. in this section).

JavaScript

Thanks in advance

Advertisement

Answer

A look back: The question above did not make much sense in retrospect, because normally you create relations between tables, if you come across this question in the future, look here for a suitable solution.

I don’t write all my code in here because it’s a lot, but I have rearranged my tables a bit and W3schools has helped me a lot to solve the problem a bit differently.

https://www.w3schools.com/sql/sql_foreignkey.asp

https://www.w3schools.com/sql/sql_join.asp

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement