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
https://forums.phpfreaks.com/topic/15443-test-for-row-already-created/
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.