Jump to content

PHP MySQL IF table exists UPDATE


Carbon

Recommended Posts

One way to do this would be to search for a match for the username.  If a match exists, UPDATE.  If a match does not exist, INSERT.

 

$usernamematch = "Carbon";
$result = $connection->prepare("SELECT username FROM tablename WHERE username = ?");
$result->bind_param("s", $username);
$result->execute();
$result->bind_result($usernamefound);
while ($row = $result->fetch()) {
    
}
if ($usernamefound != "") {

} else {

}

Just seen something else, the update function isn't what I was looking for I don't think, I have a program and I want to keep stats of users in a database for uses such as highscores and dynamic images, so for example, page is:

 

update.php?user=usernamehere&credits=2000&time=00:30:00

 

What I want it todo is if it isn't a duplicate username then it will insert if not it will add the credits gained onto what is currently there, same with time ran (in hh:mm:ss format)

 

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.