Demont Posted November 29, 2007 Share Posted November 29, 2007 I created a chat script, used with an Iframe... Here is the output of the sumbitted information. <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT poster,chat FROM chat"); while($row = mysql_fetch_array($result)) { echo $row['poster'] ." said ". $row['chat']; echo "<br />"; } ?> And here is the input <iframe src ="more_loria.php" width="100%" height="80%"> </iframe> <?php // Connects to your Database mysql_connect("*****", "*****", "******") or die(mysql_error()); mysql_select_db("joshar16_loria") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (($_POST['poster'] == "")||($_POST['chat']=="")) { die('You did not complete all of the required fields'); } $itemcheck = $_POST['chat']; $check = mysql_query("SELECT chat FROM chat WHERE chat = '$chatcheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the post '.$_POST['chat'].' already exists.'); } // now we insert it into the database $insert = "INSERT INTO chat (chat, poster) VALUES ('".$_POST['chat']."', '".$_POST['poster']."')"; $add_member = mysql_query($insert); ?> <?php } else { ?> <?php } ?> <center> <form action="more.php" method="post"> <table border="0"> <tr><td>Username:</td><td> <input type="text" name="poster" maxlength="60"> </td></tr> <tr><td>Message:</td><td> <input type="text" name="chat" maxlength="99999"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="submit"></th></tr> </table> </form> </center> </body> </html> It works, but what I don't understand is that each time one of my users refreshes, thier last message shows up again. (edited by kenrbnsn to remove users information) Quote Link to comment https://forums.phpfreaks.com/topic/79461-solved-how-to-stop-messages-from-posting-over-and-over/ Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 Look at this query $check = mysql_query("SELECT chat FROM chat WHERE chat = '$chatcheck'") or die(mysql_error()); Where is the variable $chatcheck coming from? Shouldn't it be $itemcheck? Quote Link to comment https://forums.phpfreaks.com/topic/79461-solved-how-to-stop-messages-from-posting-over-and-over/#findComment-402341 Share on other sites More sharing options...
Demont Posted November 29, 2007 Author Share Posted November 29, 2007 I didn't even see that...Thanks Poco. Quote Link to comment https://forums.phpfreaks.com/topic/79461-solved-how-to-stop-messages-from-posting-over-and-over/#findComment-402346 Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 I recommend using mysql_real_escape_string() on all your variables. Also, instead of just checking if the same "words" have been said before, check for the same words said by the same person as well. If you keep it your way, two people can never say the same thing someone else already said. So I would change this $check = mysql_query("SELECT chat FROM chat WHERE chat = '$chatcheck'") or die(mysql_error()); To $poster = mysql_real_escape_string($_POST['poster']); $check = mysql_query("SELECT chat FROM chat WHERE chat = '$chatcheck' AND poster='$poster'") or die(mysql_error()); Even then it isn't a great system as the same person wouldn't be able to say something they said in the past. Quote Link to comment https://forums.phpfreaks.com/topic/79461-solved-how-to-stop-messages-from-posting-over-and-over/#findComment-402355 Share on other sites More sharing options...
Demont Posted November 29, 2007 Author Share Posted November 29, 2007 Could an admin or someone able to, change the code in my post where it shows my database details? Quote Link to comment https://forums.phpfreaks.com/topic/79461-solved-how-to-stop-messages-from-posting-over-and-over/#findComment-402362 Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 There should be a modify/edit button that you can press...it may be timed out though. Quote Link to comment https://forums.phpfreaks.com/topic/79461-solved-how-to-stop-messages-from-posting-over-and-over/#findComment-402372 Share on other sites More sharing options...
Demont Posted November 29, 2007 Author Share Posted November 29, 2007 There isn't one. Quote Link to comment https://forums.phpfreaks.com/topic/79461-solved-how-to-stop-messages-from-posting-over-and-over/#findComment-402383 Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 Well...I would change your password then =/ Quote Link to comment https://forums.phpfreaks.com/topic/79461-solved-how-to-stop-messages-from-posting-over-and-over/#findComment-402395 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.