spiceydog Posted July 18, 2008 Share Posted July 18, 2008 I just can't figure it out. And i took out the if clause just incase that was causing the problem and still nothing! Here is the entire code: <?php $mid = $_GET['mid']; include 'login.php'; if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM accounts WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { header("Location: nosession.php"); } else { ?> <?php $queryreply = "SELECT * FROM inbox WHERE mid = '$mid' ORDER BY reply" or die(mysql_error()); $resultreply = mysql_query($queryreply) or die("Couldn't execute query because: ".mysql_error()); while($rowreply = mysql_fetch_array($resultreply)){ $reply = $rowreply['reply']; $query = "SELECT * FROM inbox WHERE mid = '$mid' AND reply = '0'" or die(mysql_error()); $result = mysql_query($query) or die("Couldn't execute query because: ".mysql_error()); while($row = mysql_fetch_array($result)){ $subject = $row['subject']; $from = $row['fromwho']; $to = $row['towho']; $date = $row['date']; $id = $row['id']; $message = $row['message']; { ?> <?php if(isset($_POST['submit'])) { $username = $_COOKIE['ID_my_site']; $ipmessage = $_SERVER['REMOTE_ADDR']; $datemessage = date('m/d/y'); $postmessage = mysql_real_escape_string(trim($_POST['message'])); $bad = array("<", ">", "="); $bitch = array("FUCK YOU", "FUCK YOU", "FUCK YOU"); date_default_timezone_set('EST'); $message = str_replace($bad, $bitch, $postmessage); if ($comment == ''){ echo "<script language='JavaScript' type='text/javascript'>alert('You cant send an empty message.'); location = 'message.php?mid=$mid';</script>"; exit; } if ($from = $username) { $querycomment = "INSERT INTO inbox (towho, fromwho, date, message, subject, reply, mid, ip) VALUES ('$to', '$username', '$datemessage', '$message', '$subject', '$reply'+1, '$mid', '$ipmessage')"; mysql_query($querycomment) or die(mysql_error()); header("Location: message.php?mid=$mid"); } if ($to = $username) { $querycomment = "INSERT INTO inbox (towho, fromwho, date, message, subject, reply, mid, ip) VALUES ('$from', '$username', '$datemessage', '$message', '$subject', '$reply'+1, '$mid', '$ipmessage')"; mysql_query($querycomment) or die(mysql_error()); header("Location: message.php?mid=$mid"); } } ?> <?php if (($from == $username) || ($to == $username)) { ?> From: <?php print "$from"; ?><br /> Sent: <?php print "$date"; ?><br /> Subject: <?php print "$subject"; ?><br /><br /><br /> <?php if ($from == $username) { echo "You messaged $to:<br />"; } else { echo "$from messaged you:<br />"; } ?> <?php print "$message"; ?> <br /><br /> <?php $query = "SELECT * FROM inbox WHERE reply != '0' AND mid = '$mid' ORDER BY reply" or die(mysql_error()); $result = mysql_query($query) or die("Couldn't execute query because: ".mysql_error()); while($row = mysql_fetch_array($result)){ $from = $row['fromwho']; $to = $row['towho']; $date = $row['date']; $message = $row['message']; { ?> Response by: <?php print "$from"; ?>:<br /> Sent: <?php print "$date"; ?><br /> Message: <?php print "$message"; ?><br /><br /><br /> <?php } } ?> <br /><br /> <form action="message.php?mid=<?php print "$mid"; ?>" method="post"> <textarea cols="30" rows="3" name="message"></textarea><br /> <input type="submit" value="Reply" name="submit"></form> <?php } else { echo "<script language='JavaScript' type='text/javascript'>alert('Dont read other peoples mail.'); location = 'inbox.php';</script>"; exit; } ?> <?php } } } } } } else { header("Location: nosession.php"); } ?> The problem: Everything in this code is shown twice in a row. As if the if clause is returning both $to == $username AND $from == $username but thats not possible and anyway if i take out the if clause it still causes the same problem Quote Link to comment https://forums.phpfreaks.com/topic/115512-solved-why-is-everything-being-posted-twice/ Share on other sites More sharing options...
DeanWhitehouse Posted July 18, 2008 Share Posted July 18, 2008 what do you mean posted twice? Quote Link to comment https://forums.phpfreaks.com/topic/115512-solved-why-is-everything-being-posted-twice/#findComment-593828 Share on other sites More sharing options...
spiceydog Posted July 18, 2008 Author Share Posted July 18, 2008 I mean that everything within the if() is shown twice on the screen one after another. For example this is what the page would look like: From: user1 Sent: 07/17/08 Subject: final test You messaged user2: testtttt!! Response by: user2: Sent: 07/17/08 Message: this is my TEST ---------------------FORM HERE--------------------- From: user1 Sent: 07/17/08 Subject: final test You messaged user2: testtttt!! Response by: user2: Sent: 07/17/08 Message: this is my TEST ---------------------FORM HERE--------------------- Quote Link to comment https://forums.phpfreaks.com/topic/115512-solved-why-is-everything-being-posted-twice/#findComment-593833 Share on other sites More sharing options...
spiceydog Posted July 18, 2008 Author Share Posted July 18, 2008 I just updated my main post and posted my entire script. Quote Link to comment https://forums.phpfreaks.com/topic/115512-solved-why-is-everything-being-posted-twice/#findComment-593887 Share on other sites More sharing options...
DeanWhitehouse Posted July 18, 2008 Share Posted July 18, 2008 i havent read the whole script , but have u tried putting the message(from, sent,subject etc,) in a while loop? Quote Link to comment https://forums.phpfreaks.com/topic/115512-solved-why-is-everything-being-posted-twice/#findComment-593889 Share on other sites More sharing options...
spiceydog Posted July 18, 2008 Author Share Posted July 18, 2008 do you mean like this: while($row = mysql_fetch_array($result)){ because yah that's in the script Quote Link to comment https://forums.phpfreaks.com/topic/115512-solved-why-is-everything-being-posted-twice/#findComment-593890 Share on other sites More sharing options...
Stephen Posted July 18, 2008 Share Posted July 18, 2008 Try doing: <?php $mid = $_GET['mid']; include 'login.php'; if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM accounts WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { header("Location: nosession.php"); } else { ?> <?php $queryreply = "SELECT * FROM inbox WHERE mid = '$mid' ORDER BY reply" or die(mysql_error()); $resultreply = mysql_query($queryreply) or die("Couldn't execute query because: ".mysql_error()); while($rowreply = mysql_fetch_array($resultreply)) { $reply = $rowreply['reply']; $query = "SELECT * FROM inbox WHERE mid = '$mid' AND reply = '0'" or die(mysql_error()); $result = mysql_query($query) or die("Couldn't execute query because: ".mysql_error()); while($row = mysql_fetch_array($result)){ $subject = $row['subject']; $from = $row['fromwho']; $to = $row['towho']; $date = $row['date']; $id = $row['id']; $message = $row['message']; { ?> <?php if(isset($_POST['submit'])) { $username = $_COOKIE['ID_my_site']; $ipmessage = $_SERVER['REMOTE_ADDR']; $datemessage = date('m/d/y'); $postmessage = mysql_real_escape_string(trim($_POST['message'])); $bad = array("<", ">", "="); $bitch = array("FUCK YOU", "FUCK YOU", "FUCK YOU"); date_default_timezone_set('EST'); $message = str_replace($bad, $bitch, $postmessage); if ($comment == ''){ echo "<script language='JavaScript' type='text/javascript'>alert('You cant send an empty message.'); location = 'message.php?mid=$mid';</script>"; exit; } if ($from == $username) { $querycomment = "INSERT INTO inbox (towho, fromwho, date, message, subject, reply, mid, ip) VALUES ('$to', '$username', '$datemessage', '$message', '$subject', '$reply'+1, '$mid', '$ipmessage')"; mysql_query($querycomment) or die(mysql_error()); header("Location: message.php?mid=$mid"); } else if ($to == $username) { $querycomment = "INSERT INTO inbox (towho, fromwho, date, message, subject, reply, mid, ip) VALUES ('$from', '$username', '$datemessage', '$message', '$subject', '$reply'+1, '$mid', '$ipmessage')"; mysql_query($querycomment) or die(mysql_error()); header("Location: message.php?mid=$mid"); } } ?> <?php if (($from == $username) || ($to == $username)) { ?> From: <?php print "$from"; ?><br /> Sent: <?php print "$date"; ?><br /> Subject: <?php print "$subject"; ?><br /><br /><br /> <?php if ($from == $username) { echo "You messaged $to:<br />"; } else { echo "$from messaged you:<br />"; } ?> <?php print "$message"; ?> <br /><br /> <?php $query = "SELECT * FROM inbox WHERE reply != '0' AND mid = '$mid' ORDER BY reply" or die(mysql_error()); $result = mysql_query($query) or die("Couldn't execute query because: ".mysql_error()); while($row2 = mysql_fetch_array($result)){ $from = $row2['fromwho']; $to = $row2['towho']; $date = $row2['date']; $message = $row2['message']; { ?> Response by: <?php print "$from"; ?>:<br /> Sent: <?php print "$date"; ?><br /> Message: <?php print "$message"; ?><br /><br /><br /> <?php } } ?> <br /><br /> <form action="message.php?mid=<?php print "$mid"; ?>" method="post"> <textarea cols="30" rows="3" name="message"></textarea><br /> <input type="submit" value="Reply" name="submit"></form> <?php } else { echo "<script language='JavaScript' type='text/javascript'>alert('Dont read other peoples mail.'); location = 'inbox.php';</script>"; exit; } ?> <?php } } } } } } else { header("Location: nosession.php"); } ?> Hope it works. Quote Link to comment https://forums.phpfreaks.com/topic/115512-solved-why-is-everything-being-posted-twice/#findComment-593894 Share on other sites More sharing options...
spiceydog Posted July 19, 2008 Author Share Posted July 19, 2008 Well Stephen... I have no clue what you changed because you didnt say in your post, but i did decide to trust you and just try it. nothing changed... from my quick scan of your script all you changed was an if to an else if... was there anything else? Can anyone else help? Quote Link to comment https://forums.phpfreaks.com/topic/115512-solved-why-is-everything-being-posted-twice/#findComment-594359 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.