Jump to content

Test For Row Already Created


Uphoreum

Recommended Posts

Say each user had a row in a table to store information about them and I want the row to automatically be created if it's not there, but I don't want a new one to be created with the same username. So, one column would be for the username and I would create one if no rows had that username. Is there a mysql query or something for this, or do I have to cycle through each row and check if it has that username manually?
Link to comment
Share on other sites

you can also do this
[code]
$sql = "SELECT * FROM `users` WHERE users_username='$requestedUsername'";
$result = mysql_query($sql);

if (mysql_num_rows($result) == 0) {
    // username is not in the databse so continue creating the account
}
else {
    // username exists so tell the user so they can choose another one
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.