Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-21-2009, 12:15 PM Inbox help
Junior Talker

Posts: 1
Name: Dean
Trades: 0
Hi, im coding a website witch has a pm system ive got pm system all coded but im not to sure how to make it so when somone pm's you they get a message show to tell them. This is my code:

messages.php
PHP Code:
<? 
ob_start
(); 
//the above line needs to be above ALL HTML and PHP (except for <?). 
include("config.php"); 
//gets the config page, which connects to the database and gets the user's information 
if ($logged[username]) 

//checks to see if they are logged in 
switch($_GET[page]) 

//this allows us to use one page for the entire thing 
default: 
Echo
"
<meta http-equiv='refresh' content='0;URL=messages.php?page=inbox'>
"

break; 
case 
'write'
if (!
$_POST[send]) 

//the form hasnt been submitted yet.... 
echo ("
<a href='messages.php'>Go Back</a><br><br>
<form method=\"POST\" style=\"margin: 0px;\"> 
     <dl style=\"margin: 0px;\"> 
             <dt>recipient</dt> 
             <dd> 
             <select name='to'> 
"
); 
$getusers mysql_query("SELECT * FROM users ORDER BY 'username' ASC"); 
             while (
$users MySQL_Fetch_Array($getusers)) { 
     echo (
"<option value=\"$users[username]\">$users[username]</option>"); 

//the above line gets all the members names and puts them in a drop down box 
echo (
</select> 
</dd> 
<dt>Message Subject</dt> 
<dd><input type=\"text\" name=\"subject\" size=\"20\"></dd> 
<dt>Message</dt> 
<dd><textarea rows=\"7\" name=\"message\" cols=\"35\"></textarea> 
</dd><dt> </dt> 
<dd><input type=\"submit\" value=\"Submit\" name=\"send\"></dd> 
</dl> 
</form>
"
); 

if (
$_POST[to]) 

//the form has been submitted.  Now we have to make it secure and insert it into the database 
$subject htmlspecialchars(addslashes("$_POST[subject]")); 
$message htmlspecialchars(addslashes("$_POST[message]")); 
$to htmlspecialchars(addslashes("$_POST[to]")); 
//the above lines remove html and add \ before all " 
$send mysql_query("INSERT INTO `pmessages` ( `title` , `message` ,  
`touser` , `from` , `unread` ,  
`date` ) VALUES ('
$subject', '$message', '$to',  
'
$logged[username]', 'unread', NOW())"); 
echo (
"
<a href='messages.php?page=inbox'>Go Back</a><br><br>
Your message has been sent."
); 

break; 
case 
'delete'
if (!
$_GET[msgid]) 

echo (
"
<a href='messages.php?page=inbox'>Go Back</a><br><br>
Sorry, but this is an invalid message.
"
); 

else 

$getmsg mysql_query("SELECT * from pmessages where id = '$_GET[msgid]'"); 
$msg mysql_fetch_array($getmsg); 
//hmm..someones trying to delete someone elses messages!  This keeps them from doing it 
if ($msg[touser] != $logged[username]) 

echo (
"
<a href='messages.php?page=inbox'>Go Back</a><br><br>
This message was not sent to you!
"
); 

else 

$delete  mysql_query("delete from pmessages where id = '$_GET[msgid]'"); 
echo (
"
<a href='messages.php?page=inbox'>Go Back</a><br><br>
Message Deleted!
"
); 


break; 
case 
'deleteall'
$delete  mysql_query("delete from pmessages where touser = '$logged[username]'"); 
echo (
"
<a href='messages.php?page=inbox'>Go Back</a><br><br>
All Message Deleted!
"
); 
break;
case 
'inbox'
$get mysql_query("SELECT * from pmessages where touser = '$logged[username]' order by id desc"); 
echo(

<a href='messages.php?page=write'>Create New Message</a><br><br>
<a href='messages.php?page=deleteall'>Delete All Messages</a><br><br>
<table border=\"0\" width=\"100%\" cellspacing=\"0\"> 
<tr> 
<td align=\"center\" style=\"border-bottom:#000000 solid 1px;\">Subject</td> 
<td align=\"center\" width=\"125\" style=\"border-bottom:#000000 solid 1px;\">From</td> 
<td align=\"center\" width=\"97\" style=\"border-bottom:#000000 solid 1px;\">Date</td> 
<td width=\"25\" style=\"border-bottom:#000000 solid 1px;\">Delete</td> 
</tr> 
</table> 
"
); 
$nummessages mysql_num_rows($get); 
if (
$nummessages == 0

echo (
"You have 0 messages!"); 

else 

echo(
"<table border=\"0\" width=\"100%\" cellspacing=\"1\">"); 
while (
$messages mysql_fetch_array($get)) 

//the above lines gets all the messages sent to you, and displays them with the newest ones on top 
echo (
<tr> 
<td><a href=\"messages.php?page=view&msgid=
$messages[id]\">"); 
if (
$messages[reply] == yes

echo (
"Reply to: "); 

echo (
"$messages[title]</a></td> 
<td width=\"125\">
$messages[from]</td> 
<td width=\"97\">
$messages[date]</td> 
<td width=\"25\"><a href=\"messages.php?page=delete&msgid=
$messages[id]\">Delete</a></td> 
</tr>"
); 

echo (
"</table>"); 

break; 
case 
'view'
//the url now should look like ?page=view&msgid=# 
if (!$_GET[msgid]) 

//there isnt a &msgid=# in the url 
echo ("
<a href='messages.php?page=inbox'>Go Back</a><br><br>
Invalid message!"
); 

else 

//the url is fine..so we continue... 
$getmsgmysql_query("SELECT * from pmessages where id = '$_GET[msgid]'"); 
$msg mysql_fetch_array($getmsg); 
//the above lines get the message, and put the details into an array. 
if ($msg[touser] == $logged[username]) 

//makes sure that this message was sent to the logged in member 
if (!$_POST[message]) 

//the form has not been submitted, so we display the message and the form 
$markread mysql_query("Update pmessages set unread = 'read' where id = '$_GET[msgid]'"); 
//this line marks the message as read. 
$msg[message] = nl2br(stripslashes("$msg[message]")); 
//removes slashes and converts new lines into line breaks. 
echo ("<a href='messages.php?page=inbox'>Go Back</a><br><br>
<form method=\"POST\" style=\"margin: 0px;\"> 
<dl style=\"margin: 0px;\"> 
<dt><b>
$msg[title] -- From $msg[from]</b></dt> 
<dd>
$msg[message]</dd> 
<dt><b>Reply</b></dt> 
<dd><textarea rows=\"6\" name=\"message\" cols=\"45\"></textarea></dd> 
<dt> </dt> 
<dd><input type=\"submit\" value=\"Submit\" name=\"send\"></dd> 
</dl></form>"
); 

if (
$_POST[message]) 

//This will send the Message to the database
$message htmlspecialchars(addslashes("$_POST[message]")); 
$do mysql_query("INSERT INTO `pmessages` ( `title` , `message` , `touser` , `from` , `unread` ,  
`date`, `reply`) VALUES 
('
$msg[title]', '$message', '$msg[from]', '$logged[username]', 
  'unread', NOW(), 'yes')"
); 
echo (
"
<a href='messages.php?page=inbox'>Go Back</a><br><br>
Your message has been sent"
); 
$getrecipient mysql_query("SELECT * FROM users WHERE user = '$to'");
$recipient mysql_fetch_assoc($getrecipient);
mail($recipient[username], "You have a new private message!""You have a new private message from: <strong>" $logged['username'] . "</strong> /n/n Click <a href=\"http://speed-racing.netau.net/messages.php?page=inbox\">here</a> to view it.""From: deanbotey@hotmail.co.uk"); 


else 

//This keeps users from veiwing other users comments
echo("
<a href='messages.php?page=inbox'>Go Back</a><br><br>
<b>Error</b><br />"
); 
echo (
"This message was not sent to you!"); 
}} 
Echo
"
</td>
             </tr>
</table>
"
;
break; 


?>
Sorry about the code being so long
dean7 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-21-2009, 02:46 PM Re: Inbox help
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Surely a
PHP Code:
if(/* new mail */){
echo 
"You got mail!";

Would work?
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-22-2009, 12:39 AM Re: Inbox help
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
you need to write that code in the main page for members area or a page called check mail or something like that.
where $logged[username] is the username for the logged user
PHP Code:
$num=mysql_result(mysql_query("select count(*) from messages where touser = '$logged[username]'"),0); 
if(
$num>0)
    echo 
"you have new mail";
else
    echo 
"no new mail"
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Inbox help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12276 seconds with 12 queries