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? Link to comment https://forums.phpfreaks.com/topic/111388-chat-php/ 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."); } Link to comment https://forums.phpfreaks.com/topic/111388-chat-php/#findComment-571798 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 Link to comment https://forums.phpfreaks.com/topic/111388-chat-php/#findComment-571809 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)); ?>" /> Link to comment https://forums.phpfreaks.com/topic/111388-chat-php/#findComment-571856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.