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
Share on other sites

Okay, I do have a login/registration system.

 

So if I add this:

CREATE TABLE messages
(
id IDENTITY(1,1) PRIMARY KEY, 
content text, 
sender varchar(35) 
); 

 

It will create a database that can successfully store PMs, right?

Link to comment
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
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
Share on other sites

<?php
//db_connect.php
$con = mysql_connect("____","____","____") or die(mysql_error());
$db = mysql_select_db("zoka_3628910_messages",$con);

function protect($string)
{
$string = mysql_real_escape_string($string);
return $string;
}
?>

 

???

Link to comment
Share on other sites

Nevermind! I got that part, now to see if it works....

 

What does this mean:

Column count doesn't match value count at row 1

 

What should I insert as the value of the sender? $_SESSION['username'] ?

Link to comment
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
Share on other sites

But my members don't have numerical IDs...well they do, but wouldn't it just be easier to select

where to_userid = $_SESSION['username'] ?

 

EDIT:

 

I got it to work! How could I have members delete a PM, though?

Link to comment
Share on other sites

well yes but if you're going to do that, I would change from_userid and to_userid to:

  `from` varchar(250)

  `to` varchar(250)

 

Okay. Thanks :)

 

How do I get people to delete a PM?

Link to comment
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
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
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
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
Share on other sites

LtfOL, no session_start(); wasn't in there before. And I'll change to_userid and from_userid when I get a chance. :P

 

Sadly, I cannot test the new code because my ISP blocked my website or something. I need to talk with them about it...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.