Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

"Missing argument 1 for function" error in PHP

Posted on 2009-05-19
3
Medium Priority
?
1,124 Views
Last Modified: 2013-12-12
I haven't posted the whole page's code but I will if I need to. I've just included all the parts related to this function.

I'm trying to make a function (funhc) to display the contents of an array later in the page. But when I try the code, I get the following error:
Warning: Missing argument 1 for funhc(), called in test3.php on line 338 and defined in test3.php on line 308

I have 5 different functions that work similarly and I receive the error on all of them. Could anyone help me and point out where my mistake is?
<?php do { ?>
  <?php
				
//tests to see if the last change value is empty (therefore never set)
if (isset($row_taskshc['update'])) {
				
$thisday = date("Y-m-d");
						
//sets the last change date to a variable $date
$date = $row_taskshc['update']; 
 
//format the date for mktime() function -- you need day, month, year
$year = substr($date, 0,4); 
$month = substr($date, 5, 2); 
$day = substr($date, 8, 2); 
 
//sets the frequency to a variable $freq
$freq = $row_taskshc['freq'];
 
//sets the variable to hold the new date. Calculates the new date by 
//evaluating the lastchange date and adding the frequency amount measured in months
$new_datecar = date("Y-m-d", mktime(0, 0, 0, $month +$freq, $day , $year)); 
 
date_diff("$thisday", "$new_datecar");
						
							
if ($ndays <= 15) {
$arrhc[] = array('task' => $row_taskshc['task'], 'adate' => $new_datecar); 
 }		
}
} while ($row_taskshc = mysql_fetch_assoc($taskshc)); 
 
function funhc($arrhc) {
if(empty($arrhc))
   {     return false;   }
	foreach($arrhc as $element) 	{
	$hc_taskelm = $element["task"];
	$hc_dateelm = $element["adate"];
	echo "<b>$hc_taskelm</b> is due on <b>$hc_dateelm</b><br /><br />";
	}
	}
 
funhc();
?>

Open in new window

0
Comment
Question by:kentcommunications
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
tg_wilk earned 500 total points
ID: 24424717
If you want to be able to omit some arguments, try assigning the default value. Furthermore, checking for array seems more appropriate then checking if the argument is empty.
function funhc($arrhc = NULL) {
if(!is_array($arrhc))
   {     return false;   }
        foreach($arrhc as $element)     {
        $hc_taskelm = $element["task"];
        $hc_dateelm = $element["adate"];
        echo "<b>$hc_taskelm</b> is due on <b>$hc_dateelm</b><br /><br />";
        }
}

Open in new window

0
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 500 total points
ID: 24425107
Your mistake is that you are calling funhc like this

funhc();

rather than like this

funhc( $someVariableOrOther );

Either pass a variable or alter the function definition as tg_wilk has outlined.
0
 

Author Closing Comment

by:kentcommunications
ID: 31583138
Works correct now. A big thanks to both of you!
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question