grlayouts Posted June 22, 2008 Share Posted June 22, 2008 hi, i have a chat box just a sim php one with the code <input name="submit2" type="submit" value="Say it!" /> <?php if ($action == postmsg) { if (empty ($chat)) { print "Duh... fill out all fields."; exit; } mysql_query("insert into tagboard (name, comments, date) values('$stat[user]','$chat',now())") or die("Could not add updates."); } ?> because this is on my main page alot of people hit f5 to reload and it posts the message again. is there any way to chnage the code so that you cant post the same message twice? Quote Link to comment Share on other sites More sharing options...
0perator Posted June 22, 2008 Share Posted June 22, 2008 } $query = mysql_query("SELECT * FROM tagboard WHERE comments = '$chat'"); $rows = mysql_num_rows($query); if($rows != 0) die('MEssage already posted'); mysql_query("insert into tagboard (name, comments, date) values('$stat[user]','$chat',now())") or die("Could not add updates."); } Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 22, 2008 Share Posted June 22, 2008 Are these registered users that are chatting? If so, when you do the check for the message being submitted twice, check that it's the same user also (Adding "AND user='$whatever'" in the query). So that if sue says "Hi" and then bob says "hi" back, his message isnt blocked Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 22, 2008 Share Posted June 22, 2008 Add a unique value in a hidden field to the form and insert that along with it, then do a search for that value OR set the column to UNIQUE in MySQL and test for an error. <input type="hidden" value="<?php echo md5(uniqid(rand(), true)); ?>" /> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.