Right now i can insert into a cell in my table from my website using the UPDATE call as follows:
$sql=“UPDATE certnumbers SET owner=‘{$_SESSION[‘logname’]}’ WHERE id=‘$_POST[verinum]’”;
I’m basically allowing the user to attach their loginname to a cell (owner) in a row identified by the id of the row.
I would ONLY like the user to add their name if the cell is blank, if its not blank and someone else has added their name already, it should give a message back to the user saying its already owned by someone else and NOT update.
Assuming that owner is NULL if nobody has claimed it yet, you can just adapt your existing query with a single condition:
UPDATE certnumbers SET owner='{$_SESSION['logname']}' WHERE id='$_POST[verinum]' AND owner IS NULL
By the looks of things you’re using PHP, so you can simply use mysql_affected_rows to find out whether the UPDATE query actually changed anything - if this function returns zero, then presumably the owner had already been set and you can display the error message.
hmmm… now i’m confused… so i currently have the following:
$sql=“UPDATE certnumbers SET owner=‘{$_SESSION[‘logname’]}’ WHERE id=‘$_POST[verinum]’ AND owner IS NOT NULL”;
this seems backwards… if someone other user’s name is in the owner column, this updates it to the new owner. it shouldn’t. it should only be updating when the owner field has nothing in it.
I thought you had it right the first time, it just didn’t update anything, owner in the field or not.
I got it thanks for the help… The column default was in fact NULL… however the column was added recently and the existing rows needed to be updated to reflect NULL