Check this out. I am trying to send the PM id in the message

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
davidprogramer
Forum Commoner
Posts: 64
Joined: Mon Nov 28, 2005 6:11 pm

Check this out. I am trying to send the PM id in the message

Post by davidprogramer »

Code: Select all

$message = "
Clan Name : $clan_name
Clan Tag : $clan_tag
Clan Status : $clan_status
Honor : $clan_honor
Ladder Name : $ladder_name

Clan Rank : $clan_rank
Clan Points : $clan_points
Clan Win % : $clan_winpercent %
Clan Wins/Losses : $clan_wins / $clan_losses
Clan Streak : $clan_streak

Clan Started on $clan_regdate
url=www.aowars.com/modules.php?name=League&file=join_clan&op=accept&lid=$current_ladder&sid=$sending_user&pid=$recieving_playerid&cid=$clan_id]<< ACCEPT >>/url]
url=www.aowars.com/modules.php?name=League&file=join_clan&op=reject&lid=$current_ladder&sid=$sending_user&pid=$recieving_playerid&cid=$clan_id]<< REJECT >>/url] ";

// Begin sending the PM.
$pm_subject = "Clan Invite from $clan_tag";
$privmsgs_date = time();

$recieving_user_profile = sql_query("SELECT user_id, username FROM ".$prefix."_users WHERE user_id = $recieving_user");
list($user_id, $username) = sql_fetch_row($recieving_user_profile);

$message = "$message";
$subject = "Clan Invite from $clan_tag";
if(empty($message) || empty($subject)) {
	return;
}
$bbcode_uid = make_bbcode_uid();
$privmsg_message = prepare_message($message, 1, 1, 1, $bbcode_uid);
$sql = "INSERT INTO nuke_bbprivmsgs (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date ) VALUES ('1', '".$subject."', '$sending_user', '$recieving_user', ".$privmsgs_date.")";
if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
{
   echo "Could not insert private message sent info";
}

$privmsg_sent_id = $db->sql_nextid();
$privmsgs_text = $message;

$sql = "INSERT INTO nuke_bbprivmsgs_text (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text) VALUES ('".$privmsg_sent_id."', '".$bbcode_uid."', '".$privmsg_message."')";
if ( !$db->sql_query($sql, END_TRANSACTION) )
{
   echo "Could not insert private message sent text";
}

$sql = "UPDATE nuke_users
		SET user_new_privmsg = user_new_privmsg + 1,  user_last_privmsg = '" . time() . "'
		WHERE user_id = '$recieving_user'";
if ( !($result = $db->sql_query($sql)) )
{
	 echo "Could not update users table";
}
See how the message is made above the queries? Well I can't think of ANY way to get the PM id inside the message. Can you guys think of a way. I am doing this so that after a player accepts or rejects an invite, it deletes the PM.
davidprogramer
Forum Commoner
Posts: 64
Joined: Mon Nov 28, 2005 6:11 pm

Post by davidprogramer »

bump~

Here is an easier version to read. Updated

Code: Select all

$sql = "INSERT INTO ".$prefix."_bbprivmsgs (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date ) VALUES ('1', '".$subject."', '$sending_user', '$recieving_user', ".$privmsgs_date.")";
if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
{
   echo "Could not insert private message sent info";
}

$lastid = mysql_insert_id($sql);
All I am trying to do is get the last insert ID. This isn't working for some reason. (I am using phpNuke. If I change !$db->sql_query to !$db->mysql_query I get an error.)

Help please~ :)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you're probably not including your database connection info on the page from which you're calling the sql_query method.

you really should get your insert id in the sql class anyway.

just write a new method to obtain your last inserted id and call it using the same object:

ex:

Code: Select all

$id = $db->getLatestId();
davidprogramer
Forum Commoner
Posts: 64
Joined: Mon Nov 28, 2005 6:11 pm

Post by davidprogramer »

What do you mean? Write my own method? As in...I could use

$id = $db->getLatestId();

anywhere to get the last id??

How would that work?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

well without seeing the class you're using for your queries, I can't really say EXACTLY how you'd need to do it.

I assume though that you have some method that utilizes your database resource (ie $result). So you could create a method that gets your inserted id.

something like this should work:

Code: Select all

function getLatestId()
{
  $this->newId = mysql_insert_id();
  return $this->newId;
}

echo $db->getLatestId();
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

function getLatestId()
{
   return mysql_insert_id();
}

:wink:
davidprogramer
Forum Commoner
Posts: 64
Joined: Mon Nov 28, 2005 6:11 pm

Post by davidprogramer »

Code: Select all

$privmsg_sent_id = $db->sql_nextid();

$message = "
Clan Name : $clan_name
Clan Tag : $clan_tag
Clan Status : $clan_status
Honor : $clan_honor
Ladder Name : $ladder_name

Clan Rank : $clan_rank
Clan Points : $clan_points
Clan Win % : $clan_winpercent %
Clan Wins/Losses : $clan_wins / $clan_losses
Clan Streak : $clan_streak

Clan Started on $clan_regdate

[url=http://www.aowars.com/modules.php?name=League&file=join_clan&op=accept&lid=$current_ladder&sid=$sending_user&pid=$recieving_playerid&cid=$clan_id&p=$privmsg_sent_id]<< ACCEPT >>[/url]
[url=http://www.aowars.com/modules.php?name=League&file=join_clan&op=reject&lid=$current_ladder&sid=$sending_user&pid=$recieving_playerid&cid=$clan_id&p=$privmsg_sent_id]<< REJECT >>[/url] ";

$message = "$message";
Got it. See where it has the next id thing. I just took the value it assigns to that and threw it in the link :-D. Such a noob mistake. Sorry.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

fyi, no point on assigning a variable to itself

Code: Select all

$message = "$message";
Might want to remove that line
davidprogramer
Forum Commoner
Posts: 64
Joined: Mon Nov 28, 2005 6:11 pm

Post by davidprogramer »

lol yeah. Thanks. Didn't even see it. ;)
Post Reply