Well hello everyone , I have this title problem. So when I type the message and press send then look in my database and conversations table is filled, conversations_members is filled, but conversations_message is empty :/. Can anyone help me?
Here's the code:
[syntax=php]
require("./connect.php");
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) VALUES ('{$subject}')");
$conversation_id = mysql_insert_id();
$sql = "INSERT INTO conversations_messages (conversation_id, user_id, message_date, message_text)
VALUES ({$conversation_id}, {$_SESSION['id']}, UNIX_TIMESTAMP(), '{$body}')";
mysql_query($sql);
$values = array();
$user_ids[] = $_SESSION['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)
VALUES " . implode(", ", $values);
mysql_query($sql);
}
create_conversation(array_unique($user_ids), $_POST['subject'], $_POST['body']);
mysql_close();
[/syntax]
Thanks .
Private Message System Pt. [08]. Can't insert messages...
-
- Posts: 5
- Joined: Sat Jun 29, 2013 10:54 am
Re: Private Message System Pt. [08]. Can't insert messages..
At line 13 of the code, replace:
[syntax=php]mysql_query($sql);[/syntax]
with
[syntax=php]mysql_query($sql) or die(mysql_error());[/syntax]
This will kill the script if any errors occur in that single query.
If there are no errors, the rest of the code AND query will be unaffected.
If any errors are presented, please post them in this thread.
Remember to replace line 13 back to what it was after debugging.
[syntax=php]mysql_query($sql);[/syntax]
with
[syntax=php]mysql_query($sql) or die(mysql_error());[/syntax]
This will kill the script if any errors occur in that single query.
If there are no errors, the rest of the code AND query will be unaffected.
If any errors are presented, please post them in this thread.
Remember to replace line 13 back to what it was after debugging.
-
- Posts: 5
- Joined: Sat Jun 29, 2013 10:54 am
Re: Private Message System Pt. [08]. Can't insert messages..
Well I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' UNIX_TIMESTAMP(), 'werwe')' at line 2
I think that UNIX_TIMESTAMP is a little bit out of date . What can I use instead?
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' UNIX_TIMESTAMP(), 'werwe')' at line 2
I think that UNIX_TIMESTAMP is a little bit out of date . What can I use instead?
Re: Private Message System Pt. [08]. Can't insert messages..
You can set a variable with time();
Eg.
[syntax=php]$thisIsTheTime = time();[/syntax]
Eg.
[syntax=php]$thisIsTheTime = time();[/syntax]
-
- Posts: 5
- Joined: Sat Jun 29, 2013 10:54 am
Re: Private Message System Pt. [08]. Can't insert messages..
So, I've done like this:
[syntax=php]
$conversation_id = mysql_insert_id();
$theTime = time();
$sql = "INSERT INTO conversations_messages ( conversation_id, user_id, message_date, message_text)
VALUES ({$conversation_id}, {$_SESSION['id']}, {$theTime}, '{$body}')";
[/syntax]
and it' says:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 1372517282, '234')' at line 2
Hmmmm :/.
[syntax=php]
$conversation_id = mysql_insert_id();
$theTime = time();
$sql = "INSERT INTO conversations_messages ( conversation_id, user_id, message_date, message_text)
VALUES ({$conversation_id}, {$_SESSION['id']}, {$theTime}, '{$body}')";
[/syntax]
and it' says:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 1372517282, '234')' at line 2
Hmmmm :/.
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Re: Private Message System Pt. [08]. Can't insert messages..
scdogas321 wrote:I think that UNIX_TIMESTAMP is a little bit out of date . What can I use instead?
Try using DATETIME.
-
- Posts: 5
- Joined: Sat Jun 29, 2013 10:54 am
Re: Private Message System Pt. [08]. Can't insert messages..
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' DATETIME, 'test')' at line 2
:/
:/
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Private Message System Pt. [08]. Can't insert messages..
What is the value of $conversation_id and session id?
<?php while(!$succeed = try()); ?>
-
- Posts: 5
- Joined: Sat Jun 29, 2013 10:54 am
Re: Private Message System Pt. [08]. Can't insert messages..
All my code is in the top.