Receiving error - Warning: Missing argument 4 for Get_All_Orderlines_Range(), called in /home/download/domains/1ecommerce.com/public_html/dev/_cms/list_orders.php on line 184 and defined in /home/download/domains/1ecommerce.com/public_html/dev/_cms/list_orders.php on line 161

Line 161:

function Get_All_Orderlines_Range($id, $all = "", $from_date, $to_date){
    $sql = "SELECT * FROM orders";
    $sql .= " INNER JOIN orderline on orders.OR_ORDER_NO = orderline.OL_ORDER_NO";
    $sql .= "  WHERE OR_CUSTOMER_ID = '$id'";
    if($all != "ALL"){ 
        if($from_date != "" and $to_date != ""){
            $sql .=" AND (orders.OR_DATE_CREATED BETWEEN '" . $from_date . "' AND '" . $to_date . "')";
        }
    }
    $sql .= " ORDER BY orderline.OL_ORDER_NO";
    //echo $sql;
    return FetchSqlAsObjectArray($sql);
}

Line 184:

$orderlines = Get_All_Orderlines_Range($printed, pack_calendar_date($from_date, "from"), pack_calendar_date($to_date, "to"));

Any help would be reallt appreciated!

Although $all is optional, it should be the last parameter for this to work. PHP cannot determine which parameters you mean.

From: http://php.net/manual/en/functions.arguments.php

"Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected."

You are only passing 3 arguments to your Get_All_Orderlines_Range() function, while it needs 4.

Do I have to have 4 arguments?

Do I have to have 4 arguments?

Not if you change the function definition to this:

function Get_All_Orderlines_Range($id, $from_date, $to_date, $all = "")

I know this responce is not needed for the original question, but could be used by people finding it later as an example.

$all is not needed. Since all is used to determine if the dates are used in an sql query, then the dates being supplied further determine the inclusion, only the later are needed, and are also optional. So, if they are not supplied in the function call, set them to 0 (zero).

function Get_All_Orderlines_Range($id, $from_date = 0, $to_date = 0){...}

Then you can remove:

if($all != "ALL"){

and just do:

if(!$from_date and !$to_date){
    $sql .=" AND (orders.OR_DATE_CREATED BETWEEN '" . $from_date . "' AND '" . $to_date . "')";
}

Here you are checking to see if both dates are supplied.

Warning:
Since this is a SELECT query, not as vital, but still important.

  • Varify that the variables are actual dates and are in the correct format before using them in sql statements.
  • Similar types of tests need to be used on the $id.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.