How to access the last record in a database table using PHP
I'm making a very simple form in PHP. It has three fields 'name', 'email' and 'comment'. Upon form submission these fields get written to a database table.
So as to prevent double data submission I'm trying to do the following: when a user clicks send, I look up the previous record in the database and compare the comment field of that record with the comment field of the data that is being submitted. If they are the same, then I would discard the submission.
a) How would I go about getting the comment field from the previously submitted record into a variable within my PHP script?
So far I have:
which (I think) gets me the previous record. But how can I access the field 'comment' from within this record. ($last.comment would work in rails).
$query = "SELECT * FROM guestbook ORDER BY id DESC limit 0,1";
$last = mysql_query($query);
b) Is this a good / sensible way to stop double data submission in a simple form.
Thanks in advance