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 :)

Recommended Answers

All 7 Replies

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

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

Like i said without that im able to like all tickets at once...

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.

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.