I have a table named 'users' that contains 'username' and 'team_name' columns. I have created form that populates two select dropdowns based on a 'username' from the users table and a 'team_name' from the 'teams' table.
I am now trying to create an insert statement that takes the 'team_name' and 'username' selected and inputs the 'team_name' into the 'users' table WHERE the 'username' is equal to one provided by the dropdown list.
$result = $conn->prepare("INSERT INTO users (`team_name`) VALUES ('{$teamname}') WHERE username = $username");
I am getting a syntax error SQLState[420000] - I think this is due to me not declaring username anywhere else within the statement i.e. columns - However, I do not want to give it a value - I just want it to post the team_name to the particuar username provided.
What is the best way to solve this?
UPDATE:
Even when using
UPDATE users SET team_name=$teamname WHERE username=$username
I still receive the error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'grillzeE' in 'where clause
When the username does exist within the username column.