Page 1 of 1

Need help w/ a bug in my private messaging script

Posted: Tue Nov 08, 2005 4:37 pm
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

Posted: Tue Nov 08, 2005 4:38 pm
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>";
                 }

Posted: Tue Nov 08, 2005 4:59 pm
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.

Posted: Tue Nov 08, 2005 5:00 pm
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.

Posted: Tue Nov 08, 2005 5:13 pm
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.

Posted: Tue Nov 08, 2005 5:19 pm
by s.dot

Code: Select all

if(!$_POST['subject'])
{
   $subject = "no subject";
} ELSE
{
   $subject = $_POST['subject'];
}

Posted: Tue Nov 08, 2005 9:54 pm
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

Posted: Tue Nov 08, 2005 11:27 pm
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];
		}

Posted: Tue Nov 08, 2005 11:35 pm
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

Posted: Thu Nov 10, 2005 7:03 pm
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 :(