Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Possible function call issue

Featured Replies

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 by Cobb

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 by Renaissance-Design

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

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 by Renaissance-Design

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 by Renaissance-Design

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

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.