S
S
Semyon Kataparov2016-04-10 19:46:25
PHP
Semyon Kataparov, 2016-04-10 19:46:25

Error writing user to database, what to do?

Here is the script itself:

if(isset($_SESSION["steamid"])) {
        $loggedIn = true;

        $steamid = $_SESSION["steamid"];
        $nickname = $_SESSION["personaname"];
        $avatarfull = $_SESSION["avatarfull"];

        mysqli_query($connect, "INSERT INTO users (steamid, name, avatar) VALUES ('$steamid', '$nickname', '$avatarfull')");
    }
    else {
        $loggedIn = false;
    }

Mistake:
Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Duplicate entry '76561198131980154' for key 'PRIMARY'' in C:\OpenServer\domains\localhost\index.php:26 Stack trace: #0 C:\OpenServer\domains\localhost\index.php(26): mysqli_query(Object(mysqli), 'INSERT INTO use...') #1 {main} thrown in C:\OpenServer\domains\localhost\index.php on line 26

It looks like it's written correctly, what's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DieZz, 2016-04-10
@truexizt1

You also wrote: Duplicate entry '76561198131980154' for key 'PRIMARY'' - an entry with the key 76561198131980154 already exists in the database. Decide on the logic of work. Use Insert or Update or Insert ignore

I
Immortal_pony, 2016-04-10
@Immortal_pony

The bracket is not closed. It should be like this:
'$avatarfull')");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question