SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: HTTP 500 error

  1. #1
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question HTTP 500 error

    Hello all,
    I was talking to Raju Gautam via PM as he had helped with the first part of the following code in this thread.

    Now all I had to do at the end of that thread was post the code in phpInputParser.php into the else statement of the code he helped me developed:
    PHP Code:
    <?php 
    if( isset($_POST['btnsearch']) ){ 
        
    $intro trim($_POST['search']); 
        
    // check if they typed introduction or intro then redirect them to introduction.html page. 
        
    if( $intro === 'introduction' || $intro === 'intro' ){ 
            
    header("Location: introduction.html"); 
            exit(); 
        } 
        else{ 
            
    // write the code in here that you wanted to do in phpInputParser.php file. 
        


    ?>
    So I pasted the entire code in phpInputParser.php inside the else's suite, but I got a 500 error saying: HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

    This error only happens when one does not type 'intro' or 'introduction' intro the input and then submit it.
    If it was 'intro' or 'introduction' then it goes to introduction.html successfully.
    Meaning Raju's code works successfully and so does phpInputParser.php (alone, when ran or viewed ina browsers alone); but, when phpInputParser is put into as the code inside the else of Raju's code, then I get the error only when that else is executed. The if statement and its code runs fine when the condition is met.

    Would someone please be willing to help me with fixing it so that the original phpInputParser.php code inside the else works properly? I think I mentioned this above, but it (phpInputParser.php) does work properly alone (when in its own file and not in the else).


    I was able, through systematically commenting parts of the code, to determine that what is causing the error is in line 31 to 57. When I remove those lines, the code inside the else runs without error, but does not do anything as lines 31 - 57 are parts of the script.

    Here is Raju's code (the if statement that redirects to introduction.html) including the else that now contains everything before and the part of the else code that is causing the error:
    PHP Code:
    if( isset($_POST['btnsearch']) ){ 
        
    $intro trim($_POST['search']); 
        
    // check if they typed introduction or intro then redirect them to introduction.html page. 
        
    if( $intro === 'introduction' || $intro === 'intro' ){ 
            
    header("Location: introduction.html"); 
            exit(); 
        } 
        else{ 
            
    // write the code in here that you wanted to do in phpInputParser.php file. 
            /*echo $intro;*/ 
    if(!session_id()){ 
        @
    session_start(); 


    ini_set('display_errors',false); 
    ini_set('error_reporting',E_ALL); 
    require_once(
    "phpsearch_files/config.php"); 

    if(
    _SEARCH_DEMO){ 
        if(isset(
    $_REQUEST['leave_demo'])){ 
            unset(
    $_SESSION['_search_demo_url']); 
        } 
        if(isset(
    $_SESSION['_search_demo_url']) && $_SESSION['_search_demo_url']){ 
            
    $GLOBALS['_SEARCH_HTML_WEBSITES'] = array( 
                
    $_SESSION['_search_demo_url'
            ); 
        } 


    /*************************************************************/ 
    /****** 500 error problem with bad-condition lies here ******/ 
    $website_search_dynamic = new website_search_dynamic(); 
    if(isset(
    $_REQUEST['search'])){ 
        
    $search_term trim($_REQUEST['search']); 
        if(
    strlen($search_term) <= 0){ 
            
    $website_search_dynamic -> error($website_search_dynamic->label("Please enter a search query."),true); 
        }else if(
    strlen($search_term) < $GLOBALS['_SEARCH_MIN_CHARS']){ 
            
    $website_search_dynamic -> error($website_search_dynamic->label("Sorry, you must enter at least %d characters in your search query",$GLOBALS['_SEARCH_MIN_CHARS']),true); 
        } 
        
    $website_search_dynamic -> search($search_term); 

    if(!isset(
    $_REQUEST['updateindex'])){ 
        echo 
    $website_search_dynamic -> render(); 

    /*************************************************************/ 
    /*************************************************************/ 

    /* about 900 more lines of code that don't cause the problem, so i didn't want to bother you with them*/ 

        


    ?> 
    Thank you all for any and all help! I would and do sincerely and really appreciate it
    Please let me know if you have any Questions, Comments, Concerns, or Solutions

    Thanks in Advance & Best Regards,
    Team 1504

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There can be many possibilities to cause the problem as you have few super global variables used with $_REQUEST. I don't know from where they come and what value you are expecting from them. Also you have included a file and I am not sure what that file contains in it.

    I can guess that you are trying to search something and validating in the area of code which you have pointed to cause the 500 error. I don't know what you are trying to search there and what result you want but better practice will be to try by adding small pieces of codes gradually from that file to the else part and run to troubleshoot.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well What was is in else was a search algorithm for posts in my blog. Would it help if I attached a zip of all the code with the includes?

    Because this is something I would prefer to fix and get done soon or that I can get done with the rest of the blog.
    I apologise for wanting it to be done soon.
    I have looked through this and asked on reddit and twitter and no one has helped me thus far. And I have read through it over and over and I can not figure it out.

  4. #4
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I have uploaded The entire file above, it's assets, and the file that calls it
    http://db.tt/3UMN0A7m
    Thank you all very much!

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm have you already given up to research yourself for solving the issue? As I already suggested try adding block by block of codes in the else part from other file. I cannot try your code in my system because there are other settings as well and I don't even have your database. Neither I have time to work for you giving much time. We are here just to give break the deadlock rather than managing all the tasks for one.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,083
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Have you tried this?

    PHP Code:
    <?php  
    if( isset($_POST['btnsearch']) ){  
        
    $intro trim($_POST['search']);  
        
    // check if they typed introduction or intro then redirect them to introduction.html page.  
        
    if( $intro === 'introduction' || $intro === 'intro' ){  
            
    header("Location: introduction.html");  
            exit();  
        }  
        else{  
            require(
    '/path/to/phpInputParser.php');
        }  
    }  
    ?>
    Seems a lot more sensible than paste a load of code in an else block, which will only make things less readable and confusing.

    Other than that I agree with what Raju just said, you're going to need to do and learn stuff yourself as well, not ask us everything
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  7. #7
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Makes sense. Sorry if I was asking and for asking too much.

    It worked, but now my script is not working properly.
    so I will attempt to understand, ir I will understand because I have to for this project, the code and how to get it working with this header redirect.

    Anyway, there is no more 500 error. Thank you!

  8. #8
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I spent most all of today reading through my old code and I got it working! Thank you all for the help and advice!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •