I m working on private messaging in website
but now i m facing logic errors in this code
so check this code and plz help me…
"pm and “userinformaton2” are the tables in mysql database
here is the code:
<?php include('config2.php'); ?> Read a PM <?php$getname=$_SESSION[‘login_user’];
$message=mysql_query(“select id from userinformation2 where username=’$getname’”) or die(mysql_error());
$row = mysql_fetch_array($message);
$getid=$row[‘id’];
//We check if the user is logged
if(isset($_SESSION[‘login_user’]))
{
//We check if the ID of the discussion is defined
if(isset($_GET[‘id’]))
{
$id = intval($_GET[‘id’]);
//We get the title and the narators of the discussion
$req1 = mysql_query(‘select title, user1, user2 from pm where id="’.$id.’" and id2=“1”’);
$dn1 = mysql_fetch_array($req1);
//We check if the discussion exists
if(mysql_num_rows($req1)==1)
{
//We check if the user have the right to read this discussion
if($dn1[‘user1’]==$getid or $dn1[‘user2’]==$getid)
{
//The discussion will be placed in read messages
if($dn1[‘user1’]==$getid)
{
mysql_query(‘update pm set user1read=“yes” where id="’.$id.’" and id2=“1”’);
$user_partic = 2;
}
else
{
mysql_query(‘update pm set user2read=“yes” where id="’.$id.’" and id2=“1”’);
$user_partic = 1;
}
//We get the list of the messages
$req2 = mysql_query(‘select pm.timestamp, pm.message, userinformation2.id as userid, userinformation2.username from pm, userinformation2 where pm.id="’.$id.’" and userinformation2.id=pm.user1 order by pm.id2’);
//We check if the form has been sent
if(isset($_POST[‘message’]) and $_POST[‘message’]!=’’)
{
$message = $_POST[‘message’];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
$message = stripslashes($message);
}
//We protect the variables
$message = mysql_real_escape_string(nl2br(htmlentities($message, ENT_QUOTES, ‘UTF-8’)));
//We send the message and we change the status of the discussion to unread for the recipient
if(mysql_query(‘insert into pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read)values("’.$id.’", “’.(intval(mysql_num_rows($req2))+1).’”, “”, “’.$_SESSION[‘userid’].’”, “”, “’.$message.’”, “’.time().’”, “”, “”)’) and mysql_query(‘update pm set user’.$user_partic.‘read=“yes” where id="’.$id.’" and id2=“1”’))
{
?>
Go to the discussion
Go to the discussion
<?php echo $dn1['title']; ?>
User | Message |
---|---|
<?php
if($dn2['avatar']!='')
{
echo ' <?php echo $dn2['username']; ?> |
Sent: <?php echo date('m/d/Y H:i:s' ,$dn2['timestamp']); ?>
<?php echo $dn2['message']; ?> |