I get a too few arguments error

Hello

Here are a call to a function
$items_l = get_all_profit($start_date, $end_date, $hour_start, $hour_end, $days);
and a function

function get_all_profit($start_date, $end_date, $hour_start, $hour_end, $days)
{	
	global $db;
	
	try
	{
		$sql = "SELECT c_time, o_time, profit, hideshow, DATE_FORMAT(c_time, '%m-%y') AS time
		        FROM data
				WHERE c_time BETWEEN :start_date AND :end_date 
			    AND TIME(`o_time`) BETWEEN :hour_start AND :hour_end
				AND WEEKDAY(`o_time`) IN ($days)				
				AND hideshow = 'hide'
				ORDER BY c_time ASC";
		$stmt = $db->prepare($sql);
		$stmt->bindParam(':start_date', $start_date, PDO::PARAM_STR);
	    $stmt->bindParam(':end_date', $end_date, PDO::PARAM_STR);
	    $stmt->bindParam(':hour_start', $hour_start, PDO::PARAM_STR);
	    $stmt->bindParam(':hour_end', $hour_end, PDO::PARAM_STR);
		$stmt->execute();
		
		if($stmt->rowCount() == 0)
		return 0;
		else
		return $stmt->fetchAll(PDO::FETCH_ASSOC);
		
	}
	catch(Exception $e) 
	{
	   return false;        
	}
}//End function

I get these errors:

  1. Fatal error: Uncaught ArgumentCountError: Too few arguments to function get_all_profit(), 1 passed in C:\wamp\www\trade_analyzer_filter_NEWֹTABLESֹ\trades_header.php on line 113 and exactly 5 expected

and
2. ArgumentCountError: Too few arguments to function get_all_profit(), 1 passed in C:\wamp\www\trade_analyzer_filter_NEWֹTABLESֹ\trades_header.php on line 113 and exactly 5 expected

Whem I call the function without agruments and the function looks like that

function get_all_profit()
{	
	global $db;
	
	try
	{
		$sql = "SELECT c_time, o_time, profit, hideshow, DATE_FORMAT(c_time, '%m-%y') AS time
		        FROM data
				WHERE hideshow = 'hide'
				ORDER BY c_time ASC";
		$stmt = $db->prepare($sql);
		$stmt->execute();
		
		if($stmt->rowCount() == 0)
		return 0;
		else
		return $stmt->fetchAll(PDO::FETCH_ASSOC);
		
	}
	catch(Exception $e) 
	{
	   return false;        
	}
}//End function

It works well.

I have a few more functions which work well when the call to the function passes 5 variables and the function gets 5 variables so there is no problem with the variables or their values

So where is the problem?

What is the solution

Perhaps no bindParam o_time?

That posted function call won’t produce that error. The actual call would be with a single value, like -

$items_l = get_all_profit($start_date);

or more likely with quotes around the list of variables, resulting in a single string value -

$items_l = get_all_profit("$start_date, $end_date, $hour_start, $hour_end, $days");

Are you sure the posted code is line 113 from the correct file? Are you sure you saved/uploaded any changes made to the code?

Slightly off-topic, but why go to the trouble (correctly) of using parameters for four out of five of the variables in the query, but not for the fifth?

The OP probably forgot about a previous thread supplying the $days value via a single prepared query place-holder using FIND_IN_SET() - It seems I miss a few crucial issues when it comes to arrays

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.