Jump to content


Photo

Break & Retun, Issues.


  • Please log in to reply
3 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 16 September 2006 - 05:07 PM

Hey Guys,
I've got a small script which detects missing fields,
and anything within the datavase which does not
match, the problem is this code is included by my
php nav script, this means when the errors are
ouputted the page stops after the exit;

Well I was wondering if I could actually use:
break; instead of the exit, and use the "return"
at the end of the script so the red of the page
can load...

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 16 September 2006 - 05:55 PM

I am having a hard time understanding the problem. Can you post the script?

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 16 September 2006 - 05:59 PM

The problem is, I have a functions file, which is included into
my index. to send a Private Message I check for several
things, the problem is with my "exit;" because I have a
php nav using if's When a problem occours, the error has an exit;
which then cuts off the remainder of my site...

So I wanted to BREAK the script. and RETURN it
at the end of the script so the rest of the site can load
and the error stays put, without adding anything to the
database.

My code:
<?php
function SendPrivMsg(){
	
	if( isset( $_POST['user'] ) && empty( $_POST['user'] ) )
		{
		$error[] = "You did not provide a Recipient. Please enter the Recipient's name.";
		}
		
	elseif( isset( $_POST['subject'] ) && empty( $_POST['subject'] ) )
		{
		$error[] = "You did not provide a Subject. Please enter the Subject.";
		}
		
	elseif( isset( $_POST['message'] ) && empty( $_POST['message'] ) )
		{
		$error[] = "You did not provide a Message. Please enter the Message.";
		}
	
			$sql_usr_exst = mysql_query("SELECT usr_user FROM accounts WHERE usr_user='".strtolower( $_POST['user'] )."'");
			$num_usr_exst = mysql_num_rows( $sql_usr_exst );
			
		if( !$num_usr_exst )
		{
		$error[] = "The Recipient's name does not exist. Please make sure you spelt it correctly.";
		}
	
			$sql_blk_chk = mysql_query("SELECT * FROM pm_buddy WHERE bdy_name='".strtolower( $_POST['user'] )."', inf_block='y', inf_friend='n'");
			$num_blk_chk = @mysql_num_rows( $sql_blk_chk );
			
		if( !$num_blk_chk )
		{
		$error[] = "The Recipient can not receive Private Messages at this time, Please try again later.";
		}
		
			$sql_ban_chk = mysql_query("SELECT pri_pm FROM accounts WHERE usr_user='".strtolower( $_POST['user'] )."'");
			$num_ban_chk = mysql_num_rows( $sql_ban_chk );
			
		if( !$num_ban_chk )
		{
		$error[] = "The Recipient does not have permission to receive Private Messages.";
		}
		
			$sql_lmt_chk = mysql_query("SELECT * FROM pm WHERE to_usr='".strtolower( $_POST['user'] )."'");
			$num_lmt_chk = mysql_num_rows( $sql_lmt_chk );
				$sql2 = mysql_query("SELECT pm_space FROM accounts WHERE usr_user='".strtolower( $_POST['user'] )."'");
				while( $data = mysql_fetch_array( $sql2, MYSQL_NUM )){
				$usr_limit = $data[0];
				}
			
		if( $num_lmt_chk >= $usr_limit )
		{
		$error[] = "The Recipient does not have enough space to store your message. Please try again later";
		}
		
			$sql_use_chk = mysql_query("SELECT pri_pm FROM accounts WHERE usr_user='{$_SESSION['username']['usr_user']}'");
			$num_use_chk = mysql_num_rows( $sql_use_chk );
			
		if( !$num_lmt_chk )
		{
		$error[] = "You do not have permission to use the Private Messenger, Or you have disabled your messenger.";
		}
		
		
			if(is_array($error))
				{
				echo "<p><UL><span class=\"error\"><b>Please correct the following errors:</b></span><br>";
				foreach( $error as $key => $value )
					{
					echo "<LI><span class=\"error\">" . $value . "</span></LI>";
					}
				echo "</UL></p>";
			exit;
			}
				
			if( $_POST['track'] == "y"){
			$Trk="y";
			}else{
			$Trk="n";
			}
		
		$date = date("d F o");
		$time = date("g:ia");
		$ip = getenv('REMOTE_ADDR');
		mysql_query("INSERT INTO pm (to_usr, fr_usr, subject, message, stats, icon, date, time, inf_tracker, adm_ip) VALUES ('".strtolower( $_POST['user'] )."',
		'".$_SESSION['username']['usr_user']."',
		'".$_POST['subject']."',
		'".$_POST['message']."',
		'0',
		'new_msg.PNG',
		'$date',
		'$time',
		'$Trk',
		'$ip')");
		
		$complete="<p><span class=\"heading\">Message Sent.</span><br>
<span class=\"text\">Your message has been successfully sent to ".$_POST['user'].", Please remember if this is abuse, 
spam or anything against our terms, policies or rules depending on the issue 
could result in a permanent ban.</span></p>";
		
		
		$qry_sql = mysql_query("SELECT pri_notify,usr_mail FROM accounts WHERE usr_user='".strtolower( $_POST['user'] )."'");
		while( $y = mysql_fetch_array( $qry_sql, MYSQL_NUM )){
			$AlertUsr = $y[0];
			$ToMail = $y[1];
		}
			if( $AlertUsr == "y" )
				{
				$subject="You have a new Priavte Message";
				$from="NoReply@eumod.co.uk";
				$message="To: ".strtolower( $_POST['user'] )."
				From: ".$INFO['SITE_NAME']." <$from>
				Sent: $date and $time.
				Subject: $subject.
				
				Dear ".strtolower( $_POST['user'] ).",
				You have received a NEW private message from ".$_SESSION['username']['usr_user'].", to view this message please sign into your account.
				
				Best Regards
				-".$INFO['SITE_NAME'].".";
				
				 mail($ToMail, $subject, $message, "FROM: $from");
				
			echo $complete;
				
				}
			else
			{
		
		echo $complete;
		
		}
}
?>

MOD EDIT: code tags added

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 16 September 2006 - 07:36 PM

Replace "exit;" with "return false;"

At end of script put "return true;"

Call script with

if (SendPrivMsg() ) {

     // it worked
} else {

   // there was an error
}[/code

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users