Jump to content

PM System


Cetanu

Recommended Posts

I assume you already have a login system so...

 

Make a table something along "message" or "pm" or whatever you like.

 

Add these columns to it: id (auto-increment), messagecontent (or pmcontent), idowner

 

Now make a page where you can enter two fields, username to send and content. Now after that make sure to authenticate the content and username and such secruity of course.

 

Now after its authenticated, add it to the table. Now make a page that displays every message where idowner == idplayer (Or iduser or just id or whatever its set at your website.). Then when they click on the message, display the content.

Link to comment
https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-869079
Share on other sites

I would just use:

CREATE TABLE messages
(
  `ID` int(11) NOT NULL auto_increment,
  `from_userid` int(11) NOT NULL,
  `to_userid` int(11) NOT NULL,
  `subject` varchar(250) NOT NULL,
  `content` longtext NOT NULL
  PRIMARY KEY  (`ID`)
); 

 

 

So you can hide messages to other users and only display the ones that are sent to the loged in user, so like this:

<?
print "<tr class='divider'><td width='35%'>From</td><td width='37%'>subject</td><td>Options</td></tr>";

$getmail="SELECT * from messages where `to_userid`='{$_SESSION['id']}'";

$getmail2=mysql_query($getmail) or die(mysql_error());

while($getmail3=mysql_fetch_array($getmail2))

{

  print "<tr class='divider'><td><a href='profile.php?id=$getmail3[from_userid]'>$getmail3[from_userid]</a></td><td><a href='mail_msg.php?id=$getmail3[iD]'>$getmail3[subject]</a></td><td><a href='?go=delete&id=$getmail3[iD]'>Delete</a></td></tr>";

}

print "</div></table>";

?>

 

Thats how my PM system is set up

Link to comment
https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-869234
Share on other sites

I fooled with that ^ and got these:

 

pm.php

<?php
include "db.php"; 

if(!$_POST['send'])
{	
include ("sendpm.php");
}
else
{
$subject = protect($_POST['subject']);
$content = protect($_POST['content']);
$to = protect($_POST['to']);

if(!$subject || !$to || !$content)
{
   $errors[] = "You did not fill out the required fields";
}

else
{
  $sql = "INSERT into messages (`to_userid` , `subject`,`content`)
  VALUES ('$subject','$content');";

$query = mysql_query($sql) or die(mysql_error());
echo "PM Sent";
echo "<a href=\"index.php\"> Home </a>";
}
}

print "From<br/> Subject<br/>Options<br/>";

$getmail="SELECT * from messages where `to_userid`='{$_SESSION['id']}'";

$getmail2=mysql_query($getmail) or die(mysql_error());

while($getmail3=mysql_fetch_array($getmail2))

{

  print "<a href='profile.php?username=$getmail3[from_userid]'>$getmail3[from_userid]</a><br/><a href='mail_msg.php?id=$getmail3[iD]'>$getmail3[subject]</a><br/><a href='?go=delete&id=$getmail3[iD]'>Delete</a><br/>";

}

?>

 

But it tells me all the info, but then it says NO DATABASE SELECTED when I go to send a PM. Thanks. :)

Link to comment
https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-871486
Share on other sites

if your using "from_userid" and "to_userid" the value of from should be $_SESSION['id'] and then if you want the username to show:

   $res=mysql_query("SELECT * FROM users WHERE id='$getmail3[from_userid]'");
  while($res2=mysql_fetch_array($res)){
echo "$res2[username]";
}

 

or something like that...

Link to comment
https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872373
Share on other sites

<?
switch($_GET['go']){
case 'delete':
delete();
break;
}

function delete(){
$id=$_GET['id'];

mysql_query("DELETE FROM messages WHERE ID='$id' AND `to`='{$_SESSION['username']}'");

echo "<div class='done'>Message Deleted!</div>";
}
?>

 

Fantastic! Thanks. :)

Link to comment
https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872387
Share on other sites

Nope not solved.

 

It doesn't work.

<?php
switch($_GET['go']){
case 'delete':
delete();
break;
}

function delete(){
$id=$_GET['id'];

mysql_query("DELETE FROM messages WHERE ID='$id' AND `to_userid`='{$_SESSION['username']}'");

    header('Location: http://mythscape.freezoka.com/pmindex.php');
}
?>

Link to comment
https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872409
Share on other sites

I changed it to this:

 

<?php
include "db.php"; 

switch($_GET['go']){
case 'delete';
delete();
break;
}

function delete(){
$id=$_GET['id'];

mysql_query("DELETE FROM messages WHERE `ID`='$id' AND `to_userid`='{$_SESSION['username']}'");

    header('Location: http://mythscape.freezoka.com/pmindex.php');
}
?>

 

And still now luck! :(

Link to comment
https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872969
Share on other sites

yeah that would be a good idea  :D

you only need it once though..

is it already in the file?

 

and if your using to_userid, from_userid like i said before you should probably change it to "to" and "from" if your going to use $_SESSION['username'], just so we dont get confused..

 

and try making a new file and add this to it:

<?php
include "db.php"; 

session_start();

$id=$_GET['id'];

mysql_query("DELETE FROM messages WHERE `ID`='$id' AND `to`='{$_SESSION['username']}'");

    header('Location: http://mythscape.freezoka.com/pmindex.php');
?>

Link to comment
https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-873000
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.