Mail System Issues

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
RogueTomboy
Posts: 61
Joined: Sun May 22, 2011 3:42 pm

Mail System Issues

Post by RogueTomboy »

Hello everyone, I am having an issue with my mailing system.

When I click on my icon to take to me where a user can write a message/send $$ to other users - it's fine, beautiful. (see image below)

Image

When I click on the link to where a user can see all their messages (inbox) it shows the inbox BUT it also shows a part of the mailing system (the write a message/send $$) - which I don't want there. In that extra part it shows (which it's not supposed to) it shows an error since it can't read a variable that works perfectly fine on the writing message section. (see image below)

Image

Where is my error? :(

Code: Select all

       <div id='mail'>
          <center>
          <table border='0'>
           <tr><td>
            <?php
$bypass = 0;
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysqli_query($db,$playerinfo) or die("could not get player stats!");
$playerinfo3=mysqli_fetch_array($playerinfo2);
include_once 'statpanel.php';
 ?>
 <?php
 $bypass = 0;
 
$playerhp = $playerinfo3['hpoints'];
if ($playerhp < 1)
{
  echo "You are dead!" ;
  echo "<br><a href='useitem.php>Use an Item";
  exit;
}

if(isset($_POST['sendmessage']))
{

$message = $_POST['message'];
$subject = $_POST['subject'];
$reciever = $_POST['reciever'];

$randid = rand(999,9999999);
$SQL = "INSERT into messages(pid,sender,message,subject,randid) VALUES ('$reciever','$playerinfo3[name]','$message','$subject','$randid')"; 
mysqli_query($db,$SQL) or die("could not add to messages");

echo "<center>Message Sent<b><b><br><br>";

}

/////////////////////////////////////////////see meesage list 
if(isset($_GET['messages']) || isset($_POST['messages']))
{
$bypass = 1;
echo "<b>Messages</b><br>";
	 echo "<small>";
	  print "<center>";
      print "<table border='0' width='90%' cellspacing='10'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='85%'>";
      $selectbackpack="SELECT * from messages where pid='$playerinfo3[name]' ORDER BY date DESC";
      $selectbackpack2=mysqli_query($db, $selectbackpack) or die("could not select messages");
      print "<table border='1' bordercolor='black' bgcolor='#FFFFFF'>";
      print "<tr><td></td><td>        Date        </td><td>Sender</td><td>Subject</td></tr>";
      while($selectbackpack3=mysqli_fetch_array($selectbackpack2))
      {
	  if($selectbackpack3['readm'] == 1)
	  	 {
		 echo "<tr><td><center>  NEW!  </td>";
		 }
		 else
		 {
		 echo "<tr><td><center>       </td>";
		 }
		     echo "<td><center>$selectbackpack3[date]</td><td><center>  $selectbackpack3[sender]  </td><td><center>$selectbackpack3[subject]</td><td><center><form method='post' action='profile.php'><input type='submit' value='Read'>
	   <input type='hidden' name='readmessage' value='1'>
	   <input type='hidden' name='randid' value='$selectbackpack3[randid]'>
	   <input type='hidden' name='date' value='$selectbackpack3[date]'>
	    </form></td></tr>";
	       
		   }
      print "</table>";
      print "</td></tr></table>";    
      		 echo "</small>";

}


if(isset($_POST['readmessage']))
{
$bypass = 1;
echo "<b>Read Messages</b><br><br>";
$randid = $_POST['randid'];
$date = $_POST['date'];
$updateship="Update messages SET readm='0' WHERE pid='$playerinfo3[name]' AND date='$date' AND randid='$randid'";
	    mysqli_query($db,$updateship) or die("Could not update player");
$message="SELECT * from messages where pid='$playerinfo3[name]' AND date='$date' AND randid='$randid'";
    $message2=mysqli_query($db,$message) or die("Could not get message");
    $message3=mysqli_fetch_array($db,$message2);
echo "<b>" . $message3['subject'] . "<br></b>From: " . $message3['sender'] . "      " . $message3['date'] . "<br><br>";	
echo " " . $message3['message'] . "<br><br><br><br>";
echo "<form method='post' action='profile.php'><input type='submit' value='Delete'>
	   <input type='hidden' name='deletemessage' value='1'>
	   <input type='hidden' name='randid' value='$message3[randid]'>
	   <input type='hidden' name='date' value='$message3[date]'>
	   </form>";
	   echo "<br><center><form method='post' action='mail.php'><input type='submit' value='Back to Inbox'>
	   <input type='hidden' name='messages' value='1'>
	      </form>";
}

if(isset($_POST['deletemessage']))
{
$bypass = 1;
echo "<b>Delete Messages</b><br><br>";
$randid = $_POST['randid'];
$date = $_POST['date'];
$updateback="DELETE from messages where pid='$playerinfo3[name]' AND randid='$randid' AND date='$date'";
	  mysqli_query($db, $updateback) or die("Could not delete from messages");
echo "<center>Message Deleted <b><b><br><br>";
echo "<form method='post' action='mail.php'><input type='submit' value='Back to Inbox'>
	   <input type='hidden' name='messages' value='1'>
	      </form>";
}

if(isset($_POST['givecredits']))
{
$user = $_POST['user'];
$amount = $_POST['price'];
if($playerinfo3['credits'] < $amount)
{echo "You do not have enough Credits to make this transfer";}
else
{
$randid = rand(999,999999);
$message = $playerinfo3['name'] . " has given you " . $amount . " Credits.";
$SQL = "INSERT into messages(pid,sender,message,subject,randid) VALUES ('$user','System','$message','Recieved Money','$randid')"; mysqli_query($SQL) or die("could not add to messages");
$updateship="Update players SET credits=credits+'$amount' WHERE name='$user'";
	    mysqli_query($db,$updateship) or die("Could not update player credits");
$updateship="Update players SET credits=credits-'$amount' WHERE name='$playerinfo3[name]'";
	    mysqli_query($db,$updateship) or die("Could not update player");
echo "<center>Credits transferred<b><b><br>";
}
}
if(isset($_POST['giveplat']))
{
$user = $_POST['user'];
$amount = $_POST['price'];
if($playerinfo3['platinum'] < $amount)
{echo "You do not have enough Platinum to make this transfer";}
else
{
$randid = rand(999,999999);
$message = $playerinfo3['name'] . " has given you " . $amount . " Platinum.";
$SQL = "INSERT into messages(pid,sender,message,subject,randid) VALUES ('$user','System','$message','Recieved Money','$randid')"; mysqli_query($SQL) or die("could not add to messages");
$updateship="Update players SET platinum=platinum+'$amount' WHERE name='$user'";
	    mysqli_query($db,$updateship) or die("Could not update player Platinum");
$updateship="Update players SET platinum=platinum-'$amount' WHERE name='$playerinfo3[name]'";
	    mysqli_query($db,$updateship) or die("Could not update player");
echo "<center>Platinum transferred<b><b><br>";
}
}
if($bypass != 1)
{
if(isset($_GET['user']))
{$user = $_GET['user'];}
else{$user = $player;}
echo "<center><br><br>";
 $oplayerinfo="SELECT * from players where name='$user'";
    $oplayerinfo2=mysqli_query($db,$oplayerinfo) or die("Could not get user stats");
    $oplayerinfo3=mysqli_fetch_array($oplayerinfo2);

echo "<b>Username:</b> " . $oplayerinfo3['name'] . "<br>";
echo "<b>Class:</b> " . $oplayerinfo3['pclass'] . "<br>";
echo "<b>Level:</b> " . $oplayerinfo3['level'] . "<br>";
echo "<b>Location:</b> " . $oplayerinfo3['plocation'] . "<br><br>";
echo "<b>Date Registered:</b> " . $oplayerinfo3['dateregistered'] . "<br><br>";
}
?>
           </td></td>
           <tr><td>
           <table border='0'>
                  <tr><td>
                  <div id='mail3'>
<center>
<table border='0'>
<tr><td width="370">
<?php
echo "<center><b>--------------Send Private Message -------------</b></center><br>";
echo "<br><form method='post' action='mail.php'>";
echo "Send To:  <input type='text' name='reciever' size='21'><br>";
echo "Subject :  <input type='text' name='subject' size='44'><br>";
echo "<center><textarea rows='10' cols='44' name='message' >";
echo "</textarea></center><br>";
echo "<input type='hidden' name='sendmessage' value='1'>";
echo "  <center><input type='submit' value='Send Message'></form></center>";
?>
                  </td>
                  <td width="310">
                  <center>
                  <?php
echo "<center><b>-------------Send Credits ---------------</b></center>";
echo "<form method='post' action='mail.php'>";
echo "Amount  <input type='text' name='price' size='9'>";
echo "<input type='hidden' name='givecredits' value='1'>";
echo " <input type='hidden' name='user' value='$oplayerinfo3[name]'>";
echo "  <input type='submit' value='Give Credits'>";
echo "</form><br>";
echo "<center><b>------------Send Platinum ----------------</b></center>";
echo "<form method='post' action='mail.php'>";
echo "Amount  <input type='text' name='price' size='9'>";
echo "<input type='hidden' name='giveplat' value='1'>";
echo " <input type='hidden' name='user' value='$oplayerinfo3[name]'>";
echo "  <input type='submit' value='Give Platinum'>";
echo "</form><br>";
?>
                  </div>
                  </td>
                  </tr>
                  </table>

           </td>
           </tr>
           </table>
  </div>
 </td></tr>
 </table>
</div>
 </td></tr>
 </table>
Need art? Commissions are always open!
http://www.ladytankstudios.com

Currently addicted to:
Image
Collect & Explore for pets
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Mail System Issues

Post by hallsofvallhalla »

When reading messages you are not actually on a players profile to give money so oplayer is not defined

Code: Select all

echo " <input type='hidden' name='user' value='$oplayerinfo3[name]'>";
couple ways you can fix this

if read messages is set then add
$oplayerinfo3[name]' = $player;

or real fix of if readmessages is set then by pas the give money section.
User avatar
RogueTomboy
Posts: 61
Joined: Sun May 22, 2011 3:42 pm

Re: Mail System Issues

Post by RogueTomboy »

Heya Halls and yeah I know - I have the sending money and stuff all figured out in the first image. The second image shows where a user can read their messages but for some reason the sending money/message is there as well - I don't want it there.

The error on the second image is like you said, it'd not defined, because it's not supposed to be there:P

So I want the message/send money shown in the second image to go away so that it is ONLY showing the inbox.
Need art? Commissions are always open!
http://www.ladytankstudios.com

Currently addicted to:
Image
Collect & Explore for pets
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Mail System Issues

Post by hallsofvallhalla »

I posted a resolution in my post.

If isset read messages then bypass money.
User avatar
RogueTomboy
Posts: 61
Joined: Sun May 22, 2011 3:42 pm

Re: Mail System Issues

Post by RogueTomboy »

Yeah, I'm at a total loss.

I mean - I get what you're saying about the solution but I'm not sure where it goes in my code. :S
Need art? Commissions are always open!
http://www.ladytankstudios.com

Currently addicted to:
Image
Collect & Explore for pets
User avatar
RogueTomboy
Posts: 61
Joined: Sun May 22, 2011 3:42 pm

Re: Mail System Issues

Post by RogueTomboy »

Still not getting where the code needs to go.

I realize what you're saying of what the bypass does but I'm not sure on anything else.
Need art? Commissions are always open!
http://www.ladytankstudios.com

Currently addicted to:
Image
Collect & Explore for pets
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Mail System Issues

Post by hallsofvallhalla »

just put this somewhere after your $bypass

Code: Select all

if(!isset($oplayerinfo3['name'])){$oplayerinfo3['name'] = "";}
so

Code: Select all

if($bypass != 1)
{
if(isset($_GET['user']))
{$user = $_GET['user'];}
else{$user = $player;}
if(!isset($oplayerinfo3['name'])){$oplayerinfo3['name'] = "";}
echo "<center><br><br>";


it is an ugly way to do it but will work.
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: Mail System Issues

Post by 62896dude »

Ugly and functional is better than *GORGEOUS* and non-functional! :) (Though I'm sure some people's opinions may differ, hahaha)
Last edited by 62896dude on Fri Aug 05, 2011 10:28 pm, edited 1 time in total.
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Mail System Issues

Post by Xaleph »

How could anyone disagree with that? Hideous and non-functional? That`s worse then ugly and functional :) However, if you did say: gorgeous and non-functional, there would be room for discussion :)
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: Mail System Issues

Post by 62896dude »

Wowwww that was a blonde moment by me, and I'm not even blonde :P hahahaha I definately didn't mean to write hideous, hahaha

*goes and edits previous post*
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
Post Reply

Return to “Beginner Help and Support”