xyn Posted September 16, 2006 Share Posted September 16, 2006 Hey Guys,I've got a small script which detects missing fields,and anything within the datavase which does notmatch, the problem is this code is included by myphp nav script, this means when the errors areouputted 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 pagecan load... Quote Link to comment Share on other sites More sharing options...
Orio Posted September 16, 2006 Share Posted September 16, 2006 I am having a hard time understanding the problem. Can you post the script?Orio. Quote Link to comment Share on other sites More sharing options...
xyn Posted September 16, 2006 Author Share Posted September 16, 2006 The problem is, I have a functions file, which is included intomy index. to send a Private Message I check for severalthings, the problem is with my "exit;" because I have aphp 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 itat the end of the script so the rest of the site can loadand the error stays put, without adding anything to thedatabase.My code:[code]<?phpfunction 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted September 16, 2006 Share Posted September 16, 2006 Replace "exit;" with "return false;"At end of script put "return true;"Call script with[code]if (SendPrivMsg() ) { // it worked} else { // there was an error}[/code[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.