Jump to content

Break & Retun, Issues.


xyn

Recommended Posts

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...
Link to comment
Share on other sites

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:
[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;

}
}
?>[/code]

MOD EDIT: code tags added
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.