Need help w/ a bug in my private messaging script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Need help w/ a bug in my private messaging script

Post by 4Boredom »

Hey, I came across a problem with my private messaging. First, users can can send message on a users profile, then enter in a subject and comment.
From there it notifies the user they have a message, and They can click on the subject to open it. My only problem is that when no subject is entered, it shows the sender name and date but there is nothing to click on.... how can I make it say (no subject) when nothing is entered? here is my code:

Code: Select all

if($action=="del")
        {
           $sqlDel = "delete from `$usrmssg_tbl` where `mssg_id` ='$mssg_id'";
           mysql_query($sqlDel) or die("Error..".mysql_error());
        }
        if($action=="read")
        {
           $sql = "update `$usrmssg_tbl` set `read_status` = '0' where `mssg_id` ='$mssg_id'";
           $res = mysql_query($sql) or die("Error..".mysql_error());
        }
        if($_POST[sendMssg])
        {
           $sqlIns = "insert into `$usrmssg_tbl` values('',
                                                        '$to_id',
                                                        '$from_id',
                                                        '$mssg_subject',
                                                        '$mssg_body',
                                                        '1',
                                                        NOW())";
           mysql_query($sqlIns) or die("Error...".mysql_error());
           echo "<script>
                         alert('Message has been sent successfully');
                 </script>";
           $action="";
so basically the variable I need an if/else for $mssg_subject im just not sure how to do it
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

maybe something could be added in this part instead... im just very confused

Code: Select all

if($action=="read"&&$_GET[mssg_id])
                 {
                     $sqlMssg = "select * from `$usrmssg_tbl` where `mssg_id` ='$_GET[mssg_id]'";
                     $resMssg = mysql_query($sqlMssg) or die("Error..".mysql_error());
                     $rowMssg = mysql_fetch_array($resMssg);
                     echo "<strong><u>Subject:</u></strong> $rowMssg[mssg_subject]<br><br>";
                     echo "<strong><u>Date:</u></strong> $rowMssg[mssg_date]<br><br>";
                     echo "<DIV class=\"tblborder\"><strong><u>Message:</u></strong><br> $rowMssg[mssg_body]</DIV>";
                 }
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

When the message is being submitted, have the form processing insert "No Subject" as a default if none is entered by the user.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

you would want to add this part to the page that displays the users private messages

Code: Select all

$array = mysql_fetch_assoc(mysql_query("SELECT * FROM privatemessagestable WHERE foo = '$bar'"));

if(!$array['messagetitle'])
{
    echo "<a href=\"linktomessage\">no subject</a>";
} ELSE
{
   echo "<a href=\"linktomessage\">{$array['messagetitle']}</a>";
}
Edit: or do it the way the guy above me said.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

ambivalent wrote:When the message is being submitted, have the form processing insert "No Subject" as a default if none is entered by the user.
Thats what I want to do im just not sure how to code it... I payed someone to do the system for my then they abandoned the project due to computer problems, so im stuck trying to fix it with little PHP sense.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

if(!$_POST['subject'])
{
   $subject = "no subject";
} ELSE
{
   $subject = $_POST['subject'];
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

scrotaye wrote:

Code: Select all

if(!$_POST['subject'])
{
   $subject = "no subject";
} ELSE
{
   $subject = $_POST['subject'];
}
So would it be...

Code: Select all

if(!$_POST[mssg_subject]) 
{ 
   $subject = "no subject"; 
} 
ELSE 
{ 
   $subject = $_POST[mssg_subject]; 
}
I just dont understand how it would type in the no subject before it looks to see if there are characters in the Post or not
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

This is doing nothing... I just dont understand it

Code: Select all

if(!$_POST[$mssg_subject]) 
		{ 
		$subject = "no subject"; 
			} 
		ELSE 
		{ 
		$subject = $_POST[$mssg_subject];
		}
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

First...

Where are you cleaning these?

// no validation!

$to_id
$from_id
$mssg_subject
$mssg_body


Second...

After doing validation just do the insert. Then when you take the message out for display....

Code: Select all

$row = mysql_fetch_assoc ( $result );

$subject = ( $row['mssg_subject'] == '' ? 'no subject' : $row['mssg_subject'] );
This way you don't put extra data in your db, especially bogus data. The subject column is for message subjects if it doesn't have subject leave it empty. You can also use IF() im your MySQL SELECT to check if the subject column is empty, if it is return 'no subject'! What you can do in the database is always better than doing it in scripting after you get the result!

doing it in your select...

Code: Select all

SELECT IF(mssg_subject = '', 'no subject', mssg_subject) AS subject FROM messages WHERE mid = some_id

yj
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

thanks for trying to help me guys I just dont understand this validication stuff..

I need to learn some more PHP I guess....

I had been paying my programmer in sections after certain work was done and it sucks that he abandoned me 90% thru :(
Post Reply