Jump to content

[SOLVED] Why is everything being posted twice!?


spiceydog

Recommended Posts

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

Link to comment
Share on other sites

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---------------------

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.