How can I do this in MySQL?
When a user creates an account on a website, I want a profile URL to be created for him/her. For example: http://www.domain.com/profile.php?id=111101
, the next user's URL may be: http://www.domain.com/profile.php?id=111102
Will I have to set Auto Increment?
Some of the fields I do save during the user's registration are:
$sql="INSERT INTO Members (fldFullName, fldEmail, Password, Gender, DOB)
VALUES
('$fname','$email','$pass', '$gender', '$date')";
As of now, the field for URL is: ProfileURL
Thank you.
You can create an ID column that will auto increment. However if you pass that to your URL you will have to be very careful with how you handle the query of populating said users profile (e.g. avoid this)
So you can do $sql="INSERT INTO Members (ID,fldFullName, fldEmail, Password, Gender, DOB) VALUES ('','$fname','$email','$pass', '$gender', '$date')"
Beware of user input though
You have to store an ID field with every record in your user database table and you should make it a primary key with auto_increment enabled. That way whenever a new record is added to your database table, the record will automatically be given a unique id number that will allow you to access it.
Next, when you are creating profile.php, do a check at the top of the page for the presence of an id in the $_GET array, if it exists, escape it to prevent sql injetion and do a mysql query to pull the info you need from that particular user's record. Something like this:
Now all your user's info is stored in an array called
$user
for use throughout your page.Then if you want to get fancy with it and better SEO results, look into apache
mod_rewrite
module which will allow you to do URL rewriting so that you can have URLs that look like/profile/someusername
rather than/profile.php?id=1234
. Much better!Here are some resources for getting started with mod_rewrite: