February 28, 201214 yr Seem to be having a bit of a problem calling a function from another php file. Here's my code: <?php include ("includes/includes.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; ?> This also html in this file, but all that is working fine. includes.php: <?php include 'blogpost.php'; include 'emailDetails.php'; // Connects to DB successfully function GetBlogPosts($inUrl=null, $inTagId =null) { //This function works } function GetEmailContent($inName=null) { echo "in function"; if (!empty($inName)) { $query = mysql_query("SELECT * FROM shop_email WHERE name = '$inName' ORDER BY id DESC"); } else { echo "inName empty"; } $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; } ?> When trying to run the first bit of code, all i get returned is a blank white page in firefox, and 'HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.' in chrome. By commenting things out i've worked out that everything works until the '$emailDetails = GetEmailContent($inName = $name);' line, that's when the page starts loading as blank. I've also tried commenting out the entire GetEmailContent function, apart from 'echo "in function"', and i still get the same problem. It seems to me like there's some problem actually calling the function. Any help would be massively appreciated, thank you. Edited February 28, 201214 yr by Cobb
February 28, 201214 yr You haven't terminated the line: echo $name To anyone else who might be reading this: see how quick and easy that was to spot because the OP used the code tags? Edited February 28, 201214 yr by Renaissance-Design
February 28, 201214 yr Author Although that was very stupid of me, unfortunately that's not all it is. I only added that line so i'd have some indication on screen of how far the code was getting because of these problems. I've terminated it now and i still have the same problem.
February 28, 201214 yr What editor are you using? Edit: function GetEmailContent($inName=null) { echo "in function"; if (!empty($inName)) { $query = mysql_query("SELECT * FROM shop_email WHERE name = '$inName' ORDER BY id DESC") or die('Query failed because: ' . mysql_error()); } else { echo "inName empty"; } $emailArray = array(); if (mysql_num_rows($query) > 0) { while ($row = mysql_fetch_assoc($query)) { $emailContent = new EmailDetails($row["id"], $row['name'], $row['subject'], $row['body']); array_push($emailArray, $emailContent); } } return $emailArray; } Also set error_reporting(E_ALL) as early as you can in your script. Edited February 28, 201214 yr by Renaissance-Design
February 28, 201214 yr Author Still doing the same thing. I'm editing the file directly on the server.
February 28, 201214 yr Then the only thing it could be (unless I'm blind) by a process of elimination is something to do with the EmailDetails class. Just to confirm, what happens if you change that line to: $emailContent = $row; Edited February 28, 201214 yr by Renaissance-Design
February 28, 201214 yr Author Still the same problem. Here's the code for the class. <?php class EmailDetails { public $id; public $name; public $subject; public $body; public $email; function __construct($inId=null, $inName=null, $inSubject=null, $inBody=null, $inEmail=null) { if (!empty($inId)) { $this->id = $inId; } if (!empty($inName)) { $this->name = $inName; } if (!empty($inSubject)) { $this->subject = $inSubject; } if (!empty($inBody)) { $this->body = $inBody; } if (!empty($inEmail)) { $this->email = $inEmail; } } } ?> If it's a problem with this class though I don't understand why when i made GetEmailContent do nothing else, but echo a string, it wouldn't even do that.
February 28, 201214 yr Author I hadn't closed my for each loop, i think that was all it was! Whoops. Thank you.
Create an account or sign in to comment