Localhost I post too much
Reputation: 0
Joined: 28 Apr 2007 Posts: 3402
|
Posted: Sat May 10, 2008 9:48 am Post subject: [RELEASE] Private Messaging System |
|
|
This is a very basic Private Messaging System. It is the second project i finished so far.
There is only one problem with this. I define the sender in send.php from an include file... If you use this/want to try it out you will have to change that to something else.
If you have any suggestions or compliments or anything, please tell!
98 Percent made by me. 2 Percent made by General Programming.
(i got the IP code from here, hehe!)
Oh also i give credits to the makers of PHP and MySQL and Apache2.2
Now for the code.
Form.html
This is the form they fill out to send a message. Pretty bland, i know.
| Code: |
<form action="send.php" method="POST">
Send to: <br><input type="text" name="to">
<br>
Subject: <br><input type="text" name="sub">
<br>
Your Message: <br><textarea name="msg" rows="10" cols="45"></textarea><br>
<input type="submit" value="Send">
</form>
<?php
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br><br/>";
?>
|
Send.php
This is send.php. This plops everything into the database! WOOHOO...
| Code: |
<?php
// First, we get our includes so we can define who the person logged in is! //
include("include/session.php");
include("include/definesession.php");
// Now we can grab our info using the post method and describe them in a variable //
$sendto = trim(mysql_real_escape_string($_POST["to"]));
$from = $username;
$sub = trim(mysql_real_escape_string($_POST["sub"]));
$msg = trim(mysql_real_escape_string($_POST["msg"]));
$date = date("D M d, o h:i a");
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($to)||isset($sub)||isset($msg)||!empty($to)||!empty($sub)||!empty($msg)){
// Now we connect to the database //
$con = mysql_connect("blnk","blnk","blnk");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// After we connect we must select a database //
mysql_select_db("login", $con);
// Now we are going to select the table and insert our variables int othe table //
mysql_query("INSERT INTO private_messages (`sendto`, `from`, `subject`, `message`, `date`, `ip`)
VALUES ('" . $sendto . "', '" . $from . "', '" . $sub . "', '" . $msg . "', '" . $date . "', '" . $ip . "')") or die(mysql_error());;
// Now we can close it //
mysql_close($con);
}
// Just some words... //
else {
echo "Please fill out the form"; }
?>
<?php
echo "Sending Information.....<br/>";
echo "Done! You can now hit back!<br/>";
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br><br/>";
?>
|
Inbox.php
This is inbox.php. This retrieves the sent messages (this took me a while to take out the right messages to the right people).
| Code: |
<?php
/**
* Inbox.php
*
* This is the inbox. This is where they can view messages
* sent to them. It is not to complex, i will make it better
* as i go along. I actually recently just added this.
*
*
* Written by: Bam!
* Last Updated: May 9, 2008
*/
// First, we get our includes so we can define who the person logged in is! //
include("include/session.php");
include("include/definesession.php");
// Now we connect to the database //
$con = mysql_connect("thewere","theusername","thepassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// After we connect we must select a database //
mysql_select_db("login", $con);
// Now we are going to select the table and use WHERE and ORDER BY to select the right things //
$result = mysql_query("SELECT * FROM private_messages WHERE sendto='$username' ORDER BY id ASC", $con);;
// Just incase you fucked up :) //
if (!$result) {
die( "Error, MySQL Said: " . mysql_error() );
}
// Lets display our stuff now :) //
/** I need some serious help on this part... The
look is terrible! If someone could make it
look better i would be very happy **/
echo "<table border='1'>";
echo "<tr>";
echo "<td>From</td>";
echo "<td>Subject</td>";
echo "<td>Message</td>";
echo "<td>Date</td>";
echo "</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['from'] . "</td>";
echo "<td>" . $row['subject'] . "</td>";
echo "<td>" . $row['message'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}
// This is a link back to the main control panel //
echo "</table>";
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br>";
mysql_close($con);
?>
|
_________________
|
|