Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Function call crashing PHP

    One php file has the following code in it:
    PHP Code:
        <?php
        
    include ("includes/emailRetrieve.php"); 
        
    $name $_GET['name'];
    echo 
    $name


           $emailDetails 
    GetEmailContent($inName $name);
        
            foreach (
    $emailDetails as $post)
        {
                    
    $subject $post->subject;
                    
    $body $post->body;
                    
    $email $post->email;

    echo 
    $name;
    echo 
    $subject;
    echo 
    $body;
    echo 
    $email
        
    ?>
    And is crashing when it gets to '$emailDetails = GetEmailContent($inName = $name);'.

    Here is emailRetreieve.php

    PHP Code:
    <?php
    echo "hello";
    include 
    'emailDetails.php';

    // Succesfully connects to DB.

    function GetEmailContent($inName=null)
    {
    echo 
    "in function";
        if (!empty(
    $inName))
        {
            
    $query mysql_query("SELECT * FROM shop_email WHERE name = '$inName'"); 
        }

        
    $emailArray = array();

        while (
    $row mysql_fetch_assoc($query))
        {
            
    $emailContent = new EmailDetails($row["id"], $row['name'], $row['subject'], $row['body']);
            
    array_push($emailArray$emailContent);
        }

        return 
    $emailArray

    ?>
    I know its stopping at that line because i've commented out the php from that point onwards, and the stuff before executes fine. It just throws a fit when calling the function. Any ideas why?

    Thank you.
    Last edited by Cobb; 02-28-2012 at 09:36 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    And what is the actual error? "Throwing a fit" doesn't help.

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    The page just won't load, shows blank in firefox, and gets 'HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.' in chrome.

    Even if i comment out everything in GetEmailContent apart from 'echo "in function" I still get the same problem. There seems to be something about the actual function call that stops it working.
    Last edited by Cobb; 02-28-2012 at 09:41 AM.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by Cobb View Post
    And is crashing when it gets to '$emailDetails = GetEmailContent($inName = $name);'.
    You can't (to the best of myknowledge) assign a value to a variable inside a function call like that.

    Do it a line above:
    $inName = $name;
    $emailDetails = GetEmailContent($inName);
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Regular Coder
    Join Date
    Jan 2012
    Posts
    134
    Thanks
    0
    Thanked 32 Times in 32 Posts
    Quote Originally Posted by Cobb View Post
    The page just won't load, shows blank in firefox, and gets 'HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.' in chrome.
    Any time you get a 500 error, it means the server did in fact encounter a problem, but is not displaying the error. You can do one of two things to see the error:

    1. Look directly at the error log on the web server
    2. Use PHP to log every error, no matter how small, and also display them to you.

      PHP Code:
      error_reporting(-1);
      ini_set('display_errors''On'); 

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You can specify an assignment within a call of a function, and it will parse it as the value assigned. Its IMO abnormal to do it though.
    Other than a syntactical error in the first script since its missing its ending }, you'll need to go into the server logs to see what the problem is.

  • #7
    New Coder
    Join Date
    Sep 2011
    Posts
    80
    Thanks
    0
    Thanked 13 Times in 12 Posts
    Not related, but your foreach has no closing bracket and you really need to look at prepared statements for sql input validation.

  • Users who have thanked MarkR for this post:

    Cobb (02-28-2012)

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by Fou-Lu View Post
    You can specify an assignment within a call of a function, and it will parse it as the value assigned. Its IMO abnormal to do it though.
    I wonder then if it may be a php version problem? - How long has that been possible?

    I knew that you could do things like

    function($Foo .$Bar) but never realised assignment was possible so I've learnt something new today
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #9
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MarkR View Post
    Not related, but your foreach has no closing bracket and you really need to look at prepared statements for sql input validation.
    That seems to be exactly what it was! So stupid! But thank you!

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by tangoforce View Post
    I wonder then if it may be a php version problem? - How long has that been possible?

    I knew that you could do things like

    function($Foo .$Bar) but never realised assignment was possible so I've learnt something new today
    For sure back into the 4.x generation. I can't remember if it goes as back to the 3.x or older generations though.


  •  

    Posting Permissions

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