mysql database

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
Members Area
<?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”’))
{
?>

Your message has successfully been sent.
Go to the discussion
<?php } else { ?>
An error occurred while sending the message.
Go to the discussion
<?php } } else { //We display the messages ?>

<?php echo $dn1['title']; ?>

<?php while($dn2 = mysql_fetch_array($req2)) { ?> <?php } //We display the reply form ?>
User Message
<?php if($dn2['avatar']!='') { echo 'Image Perso'; } ?>
<?php echo $dn2['username']; ?>
Sent: <?php echo date('m/d/Y H:i:s' ,$dn2['timestamp']); ?>
<?php echo $dn2['message']; ?>

Reply

Message

<?php } } else { echo '
You dont have the rights to access this page.
'; } } else { echo '
This discussion does not exists.
'; } } else { echo '
The discussion ID is not defined.
'; } } else { echo '
You must be logged to access this page.
'; } ?>
Go to my Personal messages - Webestools

Well, first, you didn’t read the line above! You must place your code into the PHP tags so we can copy them correctly to our editors. Your code is not formatted in any way as posted and that makes it hard to follow!
I spent over an hour looking for an error and formatting it to make sense…

I did not see anything jump out of your code. It is a slightly odd way to do validation, but, should work.
What error are you getting when the code is executed. And, what have you done so far for debugging?
In other words, what are we looking for?

Thnx for reply…
but now
my problem was solved…
again thnx for reply

Sponsor our Newsletter | Privacy Policy | Terms of Service