#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171

    The script works fine but online: 500 Internal Server Error


    Hello, does anyone know why the script works fine but online I get 500 Internal Server Error? Thanks.
    PHP Code:
    $contents.="First Name"."\t";
    $contents.="Last Name"."\t";
    $contents.="Email"."\t";
    $contents.="Postcode"."\t";
    $contents.="Date of Birth"."\t";
    $contents.="Book Date"."\t";
    $contents.=$answer."\n";


    $object= new mysql($host$user$pass'12all');
    $object->connect();
    $object->select();
    $sql "
    SELECT email 
    , name 
    , NULL AS frist_name
    , NULL AS last_name
    , NULL AS postcode
    , NULL AS date_of_birth
    , NULL AS booking_date
      FROM 12all_listmembers
     WHERE active = 1
    UNION
    SELECT email
    , NULL AS name
    , first_name
    , last_name
    , NULL AS postcode
    , NULL AS date_of_birth
    , NULL AS booking_date
      FROM em_subscriber
    UNION
    SELECT emailaddress
    , NULL AS name
    , firstname
    , lastname
    , postcode
    , date_of_birth
    , new_bookings.checkin_date AS booking_date
      FROM customers
      LEFT OUTER JOIN new_bookings
                        ON new_bookings.customer_id = customers.customer_id
                        GROUP BY customers.customer_id
    "
    ;
    $object->query($sql);
    while(
    $object_res $object->fetchObject())
        {
            
    $contents.=$object_res->first_name."\t";
            
    $contents.=$object_res->last_name."\t";
            
    $contents.=$object_res->email."\t";
            
    $contents.=$object_res->postcode."\t";
            
    $contents.=$object_res->date_of_birth."\t";
            
    $contents.=$object_res->booking_date."\t";
            
    $contents.=$answer."\n";
        }
    $contents strip_tags($contents); // remove html and php tags etc.
    header('Content-type: application/ms-excel');
    header("Content-Disposition: attachment; filename=both.xls");
    print 
    $contents
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    Sydney Australia
    Posts
    183
    Rep Power
    83
    Originally Posted by zxcvbnm
    PHP Code:
    SELECT email 
    name 
    NULL AS frist_name
               
    ^^ 
    Check the spelling error.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    This is a good time to learn why you should write error-handling code. Had you written proper error handling into this script, your output would have contained an error message instead of a fatal server error with no message.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171
    Originally Posted by ManiacDan
    This is a good time to learn why you should write error-handling code. Had you written proper error handling into this script, your output would have contained an error message instead of a fatal server error with no message.
    Hey Dan, thanks for reply, 2 things though:
    1 - The script works fine on local host and generates the excel file within 1 second! This means I am not even sure if there is an error or not! Probably not.

    2 -How do you recommend me to write error handling code for this script? A simple example related to this code would be appreciated.

    BarryG, thanks for that but that didn't fix it.
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    Turn on error_reporting:

    PHP Code:
    error_reporting(E_ALL); 
    Put that at the top of your script.

    Then check the error (the function may not be called 'error'):

    PHP Code:
    $object->query($sql); 
    if ( 
    $object->error() ) {
      die(
    "SQL ERROR: <i>{$object->error()}</i><P />Thrown for: {$sql}");

    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171
    Thanks Dan;

    This line is causing the error!
    PHP Code:
    $contents strip_tags($contents); 
    I can't figure why as the error file has nothing to do with it:
    [08-Aug-2012 14:57:27] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 14:59:46] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:00:05] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:00:20] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:00:37] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:00:55] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:02:19] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:04:46] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:05:29] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:06:41] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:06:45] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:07:09] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    [08-Aug-2012 15:09:24] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
    Last edited by zxcvbnm; August 8th, 2012 at 12:10 AM.
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    What makes you think that line is causing the error?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171
    Originally Posted by ManiacDan
    What makes you think that line is causing the error?
    Hello. Well I don't quite get it cause first: Imagick? Why does it want to load imagick? Imagick is for resizing photos. I am not resizing photos here.
    Second: Line 0? No such file or directory in Unknown on line 0? I thought things start from line 1!
  16. #9
  17. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,548
    Rep Power
    2337
    Well I don't quite get it cause first: Imagick? Why does it want to load imagick? Imagick is for resizing photos. I am not resizing photos here.
    Because your PHP install is somehow configured to use imagemagick? Look at your configuration files.

    Line 0? No such file or directory in Unknown on line 0? I thought things start from line 1!
    Because it loads the libraries before it does any sort of PHP processing at all, therefore there's no PHP line number to provide.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  18. #10
  19. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    Still not understanding why you think that causes the error. There is no error here related to this line, it's all that your PHP install is misconfigured.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  20. #11
  21. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171
    Originally Posted by ManiacDan
    Still not understanding why you think that causes the error. There is no error here related to this line, it's all that your PHP install is misconfigured.
    Hey man, you are right. That was not the issue. The same script worked with another table. So I logged to phpmyadmin to check out the table. It doesn't even open!

    Looks like someone in the company has sent a large news letter and the software that does that has locked (or jammed or...) the table. The script can't get results form the table. There are 200 processes like this.

    The strange part is, after restarting mysql server, same processes popped up again!
  22. #12
  23. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by zxcvbnm
    Hey man, you are right. That was not the issue. The same script worked with another table. So I logged to phpmyadmin to check out the table. It doesn't even open!

    Looks like someone in the company has sent a large news letter and the software that does that has locked (or jammed or...) the table. The script can't get results form the table. There are 200 processes like this.

    The strange part is, after restarting mysql server, same processes popped up again!
    The sounds like some other problem.

    If the script works fine at the command-line but fails in your browser, then it's not just your database. If it were the database then the command-line run would fail, too.

    Judging by your error log, the Apache version of your PHP is configured to use ImageMagick which is failing to load, so any time any PHP file kicks off through a browser, it fails and logs that error you were seeing.

    The command-line (or CLI) version of the PHP config seems to not require ImageMagick, so it's working there.
  24. #13
  25. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0
    Spelling error in:

    SELECT email
    , name
    , NULL AS frist_name
    , NULL AS last_name
    Last edited by ManiacDan; October 5th, 2012 at 08:15 AM.
  26. #14
  27. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    Originally Posted by ksushil970
    Spelling error in:

    SELECT email
    , name
    , NULL AS frist_name
    , NULL AS last_name
    Yes, that was pointed out a month ago.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo