Cetanu Posted July 5, 2009 Share Posted July 5, 2009 I was wondering how I could go about creating a very basic PM system...keep in mind, I am fairly new to PHP. Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/ Share on other sites More sharing options...
PugJr Posted July 5, 2009 Share Posted July 5, 2009 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 More sharing options...
Cetanu Posted July 5, 2009 Author Share Posted July 5, 2009 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 https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-869216 Share on other sites More sharing options...
nbarone Posted July 5, 2009 Share Posted July 5, 2009 sender should be an int, and track the id (auto-inc) in your users table Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-869227 Share on other sites More sharing options...
adamlacombe Posted July 5, 2009 Share Posted July 5, 2009 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 More sharing options...
Cetanu Posted July 8, 2009 Author Share Posted July 8, 2009 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 More sharing options...
Cetanu Posted July 9, 2009 Author Share Posted July 9, 2009 Anyone know why? ??? Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872323 Share on other sites More sharing options...
J.Daniels Posted July 9, 2009 Share Posted July 9, 2009 Are you selecting a database in db.php?? mysql_select_db() Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872328 Share on other sites More sharing options...
9three Posted July 9, 2009 Share Posted July 9, 2009 If it's giving you an error of "No database selected".... then you need to select a database? Check to make sure your db.php has a mysql_select_db function. Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872329 Share on other sites More sharing options...
Cetanu Posted July 9, 2009 Author Share Posted July 9, 2009 <?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 https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872339 Share on other sites More sharing options...
J.Daniels Posted July 9, 2009 Share Posted July 9, 2009 Check if it selected the database: $db = mysql_select_db("zoka_3628910_messages",$con) or die('Error: '.mysql_error()); Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872340 Share on other sites More sharing options...
Cetanu Posted July 9, 2009 Author Share Posted July 9, 2009 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 https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872365 Share on other sites More sharing options...
adamlacombe Posted July 9, 2009 Share Posted July 9, 2009 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 More sharing options...
Cetanu Posted July 9, 2009 Author Share Posted July 9, 2009 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 https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872377 Share on other sites More sharing options...
adamlacombe Posted July 9, 2009 Share Posted July 9, 2009 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) Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872379 Share on other sites More sharing options...
Cetanu Posted July 9, 2009 Author Share Posted July 9, 2009 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 https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872381 Share on other sites More sharing options...
adamlacombe Posted July 9, 2009 Share Posted July 9, 2009 <? 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872382 Share on other sites More sharing options...
Cetanu Posted July 9, 2009 Author Share Posted July 9, 2009 <? 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 More sharing options...
adamlacombe Posted July 9, 2009 Share Posted July 9, 2009 No prob. if that's all, you can click "topic solved" on the bottom left of the page. Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872391 Share on other sites More sharing options...
Cetanu Posted July 10, 2009 Author Share Posted July 10, 2009 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 More sharing options...
Cetanu Posted July 10, 2009 Author Share Posted July 10, 2009 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 More sharing options...
adamlacombe Posted July 10, 2009 Share Posted July 10, 2009 post your database structure and are you using $_SESSION['id'] or $_SESSION['username']? Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872971 Share on other sites More sharing options...
Cetanu Posted July 10, 2009 Author Share Posted July 10, 2009 $_SESSION['username'] DB structure? Well there's ID, to_userid, from_userid, subject, and content. What if I added in session_start(); ? Link to comment https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-872992 Share on other sites More sharing options...
adamlacombe Posted July 10, 2009 Share Posted July 10, 2009 yeah that would be a good idea 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 More sharing options...
Cetanu Posted July 10, 2009 Author Share Posted July 10, 2009 LtfOL, no session_start(); wasn't in there before. And I'll change to_userid and from_userid when I get a chance. 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 https://forums.phpfreaks.com/topic/164813-pm-system/#findComment-873020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.