Results 1 to 5 of 5
Apr 11, 2011, 12:19 #1
- Join Date
- Jun 2007
- 164 Post(s)
- 8 Thread(s)
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:
$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