Preventing multiple SQL entrys that are same as previous?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Darkzero
Forum Newbie
Posts: 18
Joined: Thu Oct 25, 2007 8:48 pm

Preventing multiple SQL entrys that are same as previous?

Post by Darkzero »

My website is a basic form, where you post info, and it shows it on another page.. Like a messaging system, but no signing in or anything along those lines. There's five columns total in my table- post, name, email, message, IP, and date.

There's two things I wish to achieve;
-Prevent a `message` entry that's the same as the previous.
-Prevent a user's `IP` from posting more than one entry per 30 seconds (using the date column somehow?).

For the first part, my code looks something like:

Code: Select all

$last_post = mysql_query("SELECT MAX(post), message FROM `users");// "post" is a auto_increment column that numbers the posts

$message = htmlspecialchars($messagea); //variable messagea previously defined in code as a filtered $_POST

IF ( $message == $last_post ) {
die(' Duplicate entrys! ');
}
ELSE {
execute code, ect
}
I can't do that though, as someone else had pointed out to me, $message is a string, but $last_post is not. How do I go about making $last_post a string instead?


Oh, and I can't set the column `message` as UNIQUE or anything, because it's far too large.

And the second part, I really don't know where to begin. Any ideas? :\
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Using one of the mysql_fetch_* functions would probably help turn $last_post into a string for you.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

md5 the message, set the md5 as unique
Post Reply