0

Hello everyone im working on like button which im a little confuzed with my problem i have this sql and im only able to like the tickets which are in my account

$sql = "UPDATE `kladilnica` SET Liked = Liked+1 WHERE ticket_id = '".$like."' AND Username = '".$user."'";

but without this line AND Username = '".$user."' im able to like all the tickets with one button click, can someone help me how i can solve this ?
-Thank you :)

Edited by Stefan_1

3
Contributors
7
Replies
34
Views
2 Years
Discussion Span
Last Post by JorgeM
0

Possily remove AND Username = '".$user."'";

This is a guess though as I don't know about your db schema, application architecture etc.

1

If ticket_id is unique in that table, you'd only be able to update one record. If there are multiple records that have the same ticket_id, then yes, you'd update "all tickets at once".

We cant possibly know how your application works, we dont know you your db schema so its very difficult to provide you with proper guidance.

0

the ticket_id is not unique

if its not unique and is mutiple rows are going to have duplicates, then your sql logic isnt going to work. If you only want to update one row of data, then you have to find a field in that row that is unique, such as the field you use as the primary key.

0

With this code its only possible to update just one row ? so if two users click "like" it will give error ?

0

I assume that when you click the like button, regardless of the user, you would want to update the like count for one record, yes? If so, your SQL update statement needs a where clause to isolate the update to one record. For that your SQL update needs to find the row based on a unique piece of data.

Maybe I'm the one not understanding what you are trying to do.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.