I got a fatal error on INSERT

Hello saviors

I have a table that gets users data.
Each user can have numerous rows of data.
I used it successfuly without the username column in the development process.
Now I want to add username. The column exists

I changed the code and added the first row

                            $username ="user7";
			$ticket =$keywords[2];
			$o_time = $keywords[4];
			$type = $keywords[6];
			$size = $keywords[8];
			$item = substr($keywords[10], 0,  -1);
			$o_price = $keywords[12]; 
			$s_l = $keywords[14];
			$t_p = $keywords[16];
			$c_time = $keywords[18];
			$c_price = $keywords[20];
			$profit = $keywords[28];

I also changed the insert code accordingly

I run the code and I got this error message:

Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘user7’ for key ‘username’ in …

Is it because when I constructed the table I added this line:
UNIQUE KEY username (username) ?

How Do I fix the problem ?

AFAIK, as long as there should only ever be one of any given username then declaring it as UNIQUE KEY shouldn’t cause any problems.

Without knowing the exact steps to reproduce the error, my guess is you did




would have worked better.

make sure when inserting your data that there are no duplicate values for username

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.