thara Posted November 2, 2012 Share Posted November 2, 2012 can I know... there is a best way to do this logic than I have tried so far??? This is my code... //------------ Check code search bar form submission ---------------// if ( isset( $_POST['code_search_submitted'])) { if ( isset( $_POST['searchCode']) && !empty( $_POST['searchText'])) { if (is_numeric( $_POST['searchText']) && (strlen($_POST['searchText']) == 4)) { $searchCode = $_POST['searchCode']; if ( $searchCode == 1 ) { $_SESSION['searchCode'] = 'TutorCode'; } elseif ( $searchCode == 2 ) { $_SESSION['searchCode'] = 'InstituteCode'; } $_SESSION['searchText'] = $_POST['searchText']; } else { $searchingError= 'Ennter four digits for code!'; echo '<script type="text/javascript">'; echo "alert('" . $searchingError . "')"; echo "</script>"; } $url = BASE_URL . 'search/searching.php'; // Define the URL: ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { $searchingError= 'Enter Tutor or Institute Code!'; echo '<script type="text/javascript">'; echo "alert('" . $searchingError . "')"; echo "</script>"; } } //---- Check code search bar form submission ----// any comments are greatly appreciated... thank you... Quote Link to comment Share on other sites More sharing options...
Beeeeney Posted November 2, 2012 Share Posted November 2, 2012 Not quite sure what you're asking. Quote Link to comment Share on other sites More sharing options...
thara Posted November 2, 2012 Author Share Posted November 2, 2012 I am asking.. have I created above code correctly or is there another easy way to build that? (function and 'if' conditions that I have used) clear??? Quote Link to comment Share on other sites More sharing options...
Beeeeney Posted November 2, 2012 Share Posted November 2, 2012 I am asking.. have I created above code correctly or is there another easy way to build that? (function and 'if' conditions that I have used) clear??? Does it work? If so, you win! Quote Link to comment Share on other sites More sharing options...
thara Posted November 2, 2012 Author Share Posted November 2, 2012 Its working.. but I want know there is another way to this easily than I did... Quote Link to comment Share on other sites More sharing options...
Beeeeney Posted November 2, 2012 Share Posted November 2, 2012 Probably. Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted November 2, 2012 Share Posted November 2, 2012 I think it's okay, do you have the code indented? I'd indent the code to make it easier to read. Are you placing info in a database? Are you cleaning your input someway? Quote Link to comment Share on other sites More sharing options...
Christian F. Posted November 2, 2012 Share Posted November 2, 2012 I'd check for errors first, and if found: Show error message, and return to the calling function. This makes the code a lot easier to read, especially if you have a lot of possible error conditions. Then your code won't have to end up in this list. Also, as a pet peeve of mine: You shouldn't be needing to use output buffers. That tells me that you haven't properly separated the processing from the displaying, which will make your code harder to maintain and a lot more brittle and less flexible than what it should have been. Do all of the processing first, save all output into variables, and don't send a single thing (except headers) to the browser until all parsing is done. Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 2, 2012 Share Posted November 2, 2012 In the future, you might want to say what you're trying to do, if you want advice on how to do it. 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.