...

View Full Version : Function call crashing PHP



Cobb
02-28-2012, 12:21 AM
One php file has the following code in it:

<?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
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.

Fou-Lu
02-28-2012, 12:54 AM
And what is the actual error? "Throwing a fit" doesn't help.

Cobb
02-28-2012, 09:16 AM
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.

tangoforce
02-28-2012, 11:24 AM
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);

KuriosJon
02-28-2012, 12:04 PM
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:


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



error_reporting(-1);
ini_set('display_errors', 'On');

Fou-Lu
02-28-2012, 01:16 PM
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.

MarkR
02-28-2012, 01:31 PM
Not related, but your foreach has no closing bracket and you really need to look at prepared statements for sql input validation.

tangoforce
02-28-2012, 01:57 PM
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 :thumbsup:

Cobb
02-28-2012, 02:31 PM
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!

Fou-Lu
02-28-2012, 02:36 PM
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 :thumbsup:

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum