Considering the below example: HTML Page :
<input type="text" name="update_12" />
An input box with name as "update_12" and new text as : "Some another data" is sent via form to the serverside PHP script (say process.php)
Database format:
=====================
message_ID Message
=====================
12 Some data
13 Another data
If PHP script does an explode on the input name as:
foreach ($_POST as $key => $value) {
if(strstr($key, "update_")){
$required_id = explode('_',$key)[1];
$query = "UPDATE <db_name> SET `Message`='".$_POST[$key]."' WHERE `message_id`='".$required_id."'";
}
}
This updates the DB with the new message for message_ID : 12
I am new to PHP and exploring basic data storage, update, retrieval and deletions in MySQL.
Since the client can change the name of the input field :"name" and send another value to update. For example: If a client opens up firebug and changes the "name" field of input box to "update_13", his operation is going to overwrite Message of another user.
I tried researching for this by trying out a status deletion in facebook. From primary observation of the POST data for deletion I could see some important parameters being sent for deletion as :
impression_id=456ab622
profile_id=100005552221116
__user=100005552221116
story_fbid=540912345678911
For a post deletion, the associated ID looks like : story_fbid. When i changed this to may be : 540912345678912 (last digit changed) And clicked on delete, fb takes a while and responds with an error message saying : This operation cannot be done. This error message appears after the POST request to delete has been sent (with modified story_fbid). The response for the POST request contains the error message which is shown in a modal window.
I can think of a way wherein the ID and its hash (MD5/SHA1/SHA2) are stored in DB and upon receipt of id, get a hash of it and if it matches any, update that row in DB. However there are chances that (in our case) hash of 13 might match any other row and hence perform an update operation.
Can you suggest any other secure ways in which we can validate that client has not changed the values?
Answer for the question asked here is exactly what I am looking for. However there are no proper solutions/methods in that discussion.