Locking means making sure nobody else can get at it.
So you have to find a way of making sure nobody can read the data if it is locked, and that nobody can lock the data while you are busy trying to get a lock.
Remember that it is a multi-user envoriment, queries will be fires at the strangest times, including that millisecond between your select and your update. That way you could get a SELECT telling you that the record is not locked, then the other person locks the record, then you try to lock it, and the lock fails.
You can avoid this by just blindly try to lock the data first, and then see wether it worked:
UPDATE table SET locked=1, lockedby=userid
WHERE id=foo
AND locked=0;
This will try to lock the record for you if it is not locked already.
The clever bit is that you can use mysql_affected_rows() to find out how many rows were updated by this query. If the number is zero, then the query did not update any records, which means that the record was already locked (locked was 1, which is not zero, which means the WHERE clause could not find a match)
If the number is one, then the record was updated and is now locked for you.
All other queries that fetch data from the records to print them for editing must now check that they are selecting from a record that is locked by the same user who is trying to edit them:
SELECT *
FROM table
WHERE id=foo
AND userid = your_id
AND locked=1;
If the record is not locked, or locked by someone else, they query will return nothing.