开发者

I'm trying to create a database table for each user who registers. What am I doing wrong?

I am trying to work on a login and registration page and I am making a new database and i can do it fine like this:

mysql_select_db("my_db", $con);

$sql = "CREATE TABLE Persons
(
  FirstName varchar(15),
  LastName varchar(15),
 开发者_如何学Python Age int
)";

// Execute query
mysql_query($sql,$con);

and what I am trying to do is replace the "persons" with a string so that it makes a table but it is dynamic. I need a string because I am making a table for each user that registers and the new table's name is their username and password send through an md5sum encryption. I've tried this with no success it wont make a new table like the other one does :

mysql_select_db("my_db", $con);

$sql = "CREATE TABLE $data
(
  FirstName varchar(15),
  LastName varchar(15),
  Age int
)";

// Execute query
mysql_query($sql,$con);

Please help me. I've tried joining strings together with no luck so I need help.


I'm trying to create a database table for each user who registers. What am I doing wrong?

You are creating a database table for each user who registers.

This is not the way you're supposed to use relational databases. You create a row for each new user, not a table. Of course you'll need a few extra columns in your Persons table, like the Password. I'd also recommend against storing the age because that's not constant. Store the Birthday instead.

INSERT INTO Persons (FirstName, LastName, Birthday, Password)
VALUES ('John', 'Smith', '1980-07-21', 'SOME HASH HERE');

I hope you don't take it wrong, but you need to slow down a bit and learn more about SQL before trying to write more code. Trust me, it'll be better in the long run.


I'm looking back at some of the questions I've asked in the past in it's crazy to see how much I've learned in the past few years.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜