How to protect php script from the substitution information via source code?

How to protect php script from the substitution information via source code? That is, I have this button:
<a href="#" onclick="like('1'); return false;">like</a>

where 1 is the id of the news. On the server side check for the presence of such news, if there is no news echo 'error'; But here there was a following problem: when using chrome to replace the "Examine element" (Cntrl + Shift+ I) to non-existent ID, it first passes the query on ID 1, then to tampered with, that is run 2 queries.
July 2nd 19 at 14:02
3 answers
July 2nd 19 at 14:04
1) the development of clearly separate in your mind which code executes at the client (js, etc) and code that runs on the server (php)
2) General rule: on the server side, You must NOT trust data that come from client.
And more - all from the a specific task depends on the consequences, what are the conditions to check - You decide.
July 2nd 19 at 14:06
if you substitute using chrome to "Explore element" (Cntrl + Shift+ I) to non-existent ID, it first passes the query on ID 1, then to tampered with, that is run 2 queries.

And if you get a link and simulate request to third-party, there will be N number of queries, and?

No, your job is to check and give error if something goes wrong.
July 2nd 19 at 14:08
No way.Most of the users about the Developer Tools not know. Not psihice for this reason, in VK you can send 3 stickers at a time with their help.

Find more questions by tags JavaScriptPHPAJAX