Private message system PART 11 error

Ask about a PHP problem here.
Post Reply
cnbsII
Posts: 9
Joined: Thu Jun 21, 2012 8:53 am

Private message system PART 11 error

Post by cnbsII »

[syntax=php]

function fetch_conversation_summery(){

$sql = "SELECT
conversations.conversation_id,
conversations.conversation_subject,
MAX(conversations_messages.message_date) AS conversation_last_reply,
MAX(conversations_messages.message_date) > conversations_members.conversation_last_view AS conversation_unread
FROM conversations
LEFT JOIN conversations_messages ON conversations.conversation_id = conversations_messages.conversation_id
INNER JOIN conversations_members ON conversations.conversation_id = conversations_members.conversation_id
WHERE conversations_members.user_id = {$_SESSION['user_id']}
AND conversations_members.conversation_deleted = 0
GROUP BY conversations.conversation_id
ORDER BY conversation_last_reply DESC";

$result = mysql_query($sql);


$conversations = array();

while(($row = mysql_fetch_assoc($result)) !== FALSE){
$conversations[] = array(
'id' => $row['conversation_id'],
'subject' => $row['conversation_subject'],
'last_reply' => $row['conversation_last_reply'],
'unread_messages' => ($row['conversation_unread'] == 1) //it will =1 if it's true
);
}

return $conversations;
}






function create_conversation($user_ids, $subject, $body){
$subject = mysql_real_escape_string(htmlentities($subject));
$body = mysql_real_escape_string(htmlentities($body));
mysql_query("INSERT INTO conversations (conversation_subject) VALUE ('{$subject}')");



$conversation_id = mysql_insert_id();
$sql = "INSERT INTO conversations_messages (conversation_id, user_id, message_date, message_text) VALUES ({$conversation_id}, {$_SESSION['user_id']}, UNIX_TIMESTAMP(), '{$body}')";

mysql_query($sql);


$values = array();


$user_ids[] = $_SESSION['user_id'];

foreach($user_ids as $user_id){
$user_id = (int) $user_id;
$values[] = "({$conversation_id}, {$user_id}, 0, 0)";
}

$sql = "INSERT INTO conversations_members (conversation_id, user_id, conversation_last_view, conversation_deleted) VALUE " . implode(", ", $values);

mysql_query($sql);
}


//check to see if the given user is a member of the given conversation.
function validate_conversation_id($conversation_id){
$conversation_id = (int)$conversation_id;

$sql = "SELECT COUNT(1)
FROM conversations_members
WHERE conversation_id = {$conversation_id}
AND user_id = {$_SESSION['user_id']}
AND conversation_deleted = 0";

$result = mysql_query($sql);

return (mysql_result($result, 0) == 1);
}



function delete_conversation($conversation_id){
$conversation_id = (int)$conversation_id;

$sql = "SELECT DISTINCT conversation_deleted
FROM conversation_members
WHERE user_id != {$_SESSION['user_id']}
AND conversation_id = {$conversation_id}";

$result = mysql_query($sql);

if(mysql_num_rows($result) === 1 && mysql_result($result, 0) == 1){
mysql_query("DELETE FROM conversations WHERE conversation_id = {$conversation_id}");
mysql_query("DELETE FROM conversations_members WHERE conversation_id = {$conversation_id}");
mysql_query("DELETE FROM coversations_messages WHERE conversation_id = {$conversation_id}");

} else {

$sql = "UPDATE conversations_members
SET conversation_deleted = 1
where conversation_id = {$conversation_id}
AND user_id = {$_SESSION['user_id']}";

mysql_query($sql);
}

}















[/syntax]

I check over and over and all code is correct, not sure why this happen.
ERROR:

( ! ) SCREAM: Error suppression ignored for
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\betterPHP\private_message_system\core\inc\private_message.inc.php on line 97
sturekdrf
Posts: 40
Joined: Fri Jun 15, 2012 8:25 pm

Re: Private message system PART 11 error

Post by sturekdrf »

Could be wrong but for database stuff shouldnt you be using ' ' in there like below?
mysql_query("DELETE FROM 'conversations' WHERE 'conversation_id' = {$conversation_id}");
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Private message system PART 11 error

Post by Temor »

Adding[syntax=php]echo mysql_error();[/syntax] under the query that is failing should tell you what's wrong.
cnbsII
Posts: 9
Joined: Thu Jun 21, 2012 8:53 am

Re: Private message system PART 11 error

Post by cnbsII »

Temor wrote:Adding[syntax=php]echo mysql_error();[/syntax] under the query that is failing should tell you what's wrong.



after when i echo mysql_error(); there is nothing happen, and it appear the same error message.
Attachments
echo.jpg
echo.jpg (50.38 KiB) Viewed 888 times
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Private message system PART 11 error

Post by Temor »

where did you put the mysql_error(); line?

The problem appears to be at the second delete query.
[syntax=php] mysql_query("DELETE FROM conversations_members WHERE conversation_id = {$conversation_id}");[/syntax]
I would suggest you start adding backticks around your tables and rows. Like this:
[syntax=php] mysql_query("DELETE FROM `conversations_members` WHERE `conversation_id` = {$conversation_id}");[/syntax]

Are all the table and column names spelled correctly? Compare it with the names in phpmyadmin.
cnbsII
Posts: 9
Joined: Thu Jun 21, 2012 8:53 am

Re: Private message system PART 11 error

Post by cnbsII »

Temor wrote:where did you put the mysql_error(); line?

The problem appears to be at the second delete query.
[syntax=php] mysql_query("DELETE FROM conversations_members WHERE conversation_id = {$conversation_id}");[/syntax]
I would suggest you start adding backticks around your tables and rows. Like this:
[syntax=php] mysql_query("DELETE FROM `conversations_members` WHERE `conversation_id` = {$conversation_id}");[/syntax]

Are all the table and column names spelled correctly? Compare it with the names in phpmyadmin.




Hi, I put mysql_error(); in line 96, and after i test it, it have the same result. than i try again put it at line 99, also having the same error.

Also tried to put all the backticks around the tables, and i did check the spelling it match them all. Please check the attachment.
Attachments
Untitled-1.jpg
Untitled-1.jpg (56.37 KiB) Viewed 883 times
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Private message system PART 11 error

Post by jacek »

Hmm, the line number suggests that this is the failing query

[syntax=php]$sql = "SELECT DISTINCT conversation_deleted
FROM conversation_members
WHERE user_id != {$_SESSION['user_id']}
AND conversation_id = {$conversation_id}";

$result = mysql_query($sql);[/syntax]
if you added the mysql_error() like this

[syntax=php]$sql = "SELECT DISTINCT conversation_deleted
FROM conversation_members
WHERE user_id != {$_SESSION['user_id']}
AND conversation_id = {$conversation_id}";

$result = mysql_query($sql);
echo mysql_error();[/syntax]
it should have worked.

You could also try running that query in phpmyadmin to see what's going on.
Image
cnbsII
Posts: 9
Joined: Thu Jun 21, 2012 8:53 am

Re: Private message system PART 11 error

Post by cnbsII »

THANK YOU,, I FIGURE IT ALREADY, I MISSED A (S)
Last edited by jacek on Fri Jun 22, 2012 1:27 am, edited 1 time in total.
Reason: Removed massive quote.
Post Reply