Help with in site PM.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phoenixrayne
Forum Newbie
Posts: 2
Joined: Sat Mar 08, 2008 10:47 am

Help with in site PM.

Post by phoenixrayne »

Im creating an online game. I have a problem with the PM system not working. All of the hard coded messages are sent and readable. However when a user send a pm the recipient gets a blank mail. I have tried changing everything i know to change and only results i got was to manually insert the message into the code where the $ini is noted in this code. I can not get it to post to the database as a variable. The suspect spot appears to be lines 35-36.Any ideas?

Code: Select all

<?php
session_start();
include "includes/db_connect.php";
include "includes/functions.php";
logincheck();
$username=$_SESSION['username'];
 
echo "<html>
$style
<center>";
$goody = mysql_query("SELECT `message`, `date`, `from` FROM `inbox` WHERE `id`='$rep'");
while($success = mysql_fetch_row($goody)){
    $ini = $success[0];
$dateon = $success[1];
$fromper = $success[2];
    
}
if(strip_tags($_POST['Send'])){
$text= strip_tags(addslashes($_POST['text']));
$to = strip_tags(addslashes($_POST['to']));
$rep = $_GET['rep'];
 
 $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$to'");
 $username_check = mysql_num_rows($sql_username_check);
 if ($username_check == 0){
    echo '<font color=red>There is no user with that name! </font>';
}else{
$blocked=mysql_num_rows(mysql_query("SELECT * FROM friends WHERE person='$username' AND type='Blocked' AND username='$to'"));
if ($blocked != "0"){
echo "This user has blocked you.";
}elseif ($blocked == "0"){
 
 
$date = gmdate('Y-m-d h:i:s');
$sql = mysql_query("INSERT INTO `inbox` (`id`, `to`, `from`, `message`, `date`, `read`) VALUES ('', '$to', '$username', '$ini', '$date', '0');") or die (mysql_error());
if(!$sql){ 
    echo 'Error please contact an admin.'; 
    
    }else{
    echo "Message sent to <a href=profile.php?viewuser=$to><b>$to</b></a>";
 
}}}}
?>
 
 
<html>
<link href="includes/in.css" rel="stylesheet" type="text/css">
 
 
<center> 
<form action="" method="post">
  <table width="66%" border="0" align="center" cellpadding="0" cellspacing="3">
    <tr> 
      <td><table width="100%" height="21" border="1" align="center" cellpadding="0" cellspacing="0" class=thinline rules=none>
          <tr> 
            <td><table width="100%" border="0" cellspacing="3" cellpadding="0">
                <tr> 
                  <td width="53%"><div align="center"><a href="baf.php">User management</a></div></td>
                  <td width="47%"><div align="center"><a href="inbox.php">Inbox</a></div></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>
    <tr> 
      <td><table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" class=thinline rules=none>
          <tr> 
            <td class=header><div align="center">Compose a message</div></td>
          </tr>
          <tr bgcolor=white> 
            <td class=tip><div align="center">Compose a message.</div></td>
          </tr>
          <tr bgcolor=black> 
            <td height=1></td>
          </tr>
          <tr> 
            <td><table width=300 cellspacing=1 cellpadding=1 border=0 bordercolor=black class=black2 align=center>
                <tr class=title> 
                  <td width=248>Send To: </td>
                  <td width=357><input type=text name=to class=submit style=width: 60%; value='<?php echo $fromper; ?>'></td>
                </tr>
                <tr class=text> 
                  <td colspan=2>Message:</td>
                </tr>
                <tr class=sub> 
                  <td colspan=2><textarea name='text' style='width: 98%; height: 175px'  class=submit><?php if ($m > 0){ echo "[b]On:[/b] $dateon.  $fromper [b] Wrote:[/b] $ini"; }else{ } ?></textarea></td>
                </tr>
                <tr  class=title> 
                  <td colspan=2><input type=submit name=Send value=Send class=submit></td>
                </tr>
            </table></td>
          </tr>
        </table></td>
    </tr>
  </table>
  <br>
</form>
 
 
 
<?php include_once"includes/footer.php"; ?>
 
 
 
here is the table structure
TABLE `inbox` (
`id` int(11) NOT NULL auto_increment,
`to` varchar(40) NOT NULL default '',
`from` varchar(40) NOT NULL default '',
`message` text NOT NULL,
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`read` enum('0','1') NOT NULL default '0',
`saved` int(2) NOT NULL default '0',
`event_id` int(11) NOT NULL default '0',
`witness` enum('0','1') NOT NULL default '0',
`witness_per` varchar(40) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=175
Last edited by phoenixrayne on Sat Mar 08, 2008 8:39 pm, edited 1 time in total.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Help with in site PM.

Post by flying_circus »

Hi phoenixrayne,

If you suspect that a SQL query is giving you trouble, echo the query string and so that you can see what is getting passed to the DB. Then, from your browser, copy the string and try to run it manually on your SQL server. This will tell you if there is a problem with your query string, or code. Essentially it divides the troubleshooting tree either on the PHP or MySQL side.

Code: Select all

<?php
 
  ...
 
$date = gmdate('Y-m-d h:i:s');
 
echo "INSERT INTO `inbox` (`id`, `to`, `from`, `message`, `date`, `read`) VALUES ('', '$to', '$username', '$ini', '$date', '0');"
 
$sql = mysql_query("INSERT INTO `inbox` (`id`, `to`, `from`, `message`, `date`, `read`) VALUES ('', '$to', '$username', '$ini', '$date', '0');") or die (mysql_error());
 
  ...
?>
Also, without knowing more about your DB structure, why are you inserting a NULL id? If that field is auto incrementing or a primary key, you dont need to specify it in your INSERT statement and it could contribute to the problem you're having.
phoenixrayne
Forum Newbie
Posts: 2
Joined: Sat Mar 08, 2008 10:47 am

Re: Help with in site PM.

Post by phoenixrayne »

Ok i removed the auto increment and tested, with no change. I then removed the $ini and just put 'message' sent and it came up with "message" in the inbox mail. So what im getting is that the text from the text box isnt writing to the database. If i put a message in manually it sends whatever i put in there and post it to the database. Not sure why it's not taking the input from the text box.
Post Reply