Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
I’m struggling figuring this one out. For years this code worked without any issue. I have Purchase order database that our office uses to create PO’s. When the office staff want to export the entire list. They use a webform and click the date variables, and then push submit. It pops out an excel file. That was the case for years until a few weeks ago when something stopped it from working:
According to the PHPlog this is the error:
Line 28 : mysqli_fetch_fields() expects exactly 1 argument, 2 given
$filename = "Exportfullpo" . date ( 'Y-m-d' ) ;
$qReport = " SELECT ID AS PurchaseOrder, date AS Date, time AS Time, employee AS Employee, vendor AS Vendor, jobsite AS Customer, description AS Description, price - (price * 0.047619) AS SUB, price * 0.047619 AS GST, price AS Price FROM purchase WHERE date >='$startdate' AND date <='$enddate' " ;
$export = mysqli_query ( $link, $qReport ) or die ( "Sql error : " . mysqli_error ( ) ) ;
$fields = mysqli_num_fields ( $export ) ;
for ( $i = 0 ; $i < $fields; $i++ )
$header .= mysqli_fetch_fields ( $export , $i ) . "t" ;
while ( $row = mysqli_fetch_row ( $export ) )
foreach ( $row as $value )
if ( ( ! isset ( $value ) ) || ( $value == "" ) )
$value = str_replace ( '"' , '""' , $value ) ;
$value = '"' . $value . '"' . "t" ;
$data .= trim ( $line ) . "n" ;
$data = str_replace ( "r" , "" , $data ) ;
$data = "n(0) Records Found!n" ;
header ( "Content-type: application/octet-stream" ) ;
header ( "Content-Disposition: attachment; filename=$filename.xls" ) ;
header ( "Pragma: no-cache" ) ;
<code>
$filename = "Exportfullpo" . date('Y-m-d');
$qReport = " SELECT ID AS PurchaseOrder, date AS Date, time AS Time, employee AS Employee, vendor AS Vendor, jobsite AS Customer, description AS Description, price - (price * 0.047619) AS SUB, price * 0.047619 AS GST, price AS Price FROM purchase WHERE date >='$startdate' AND date <='$enddate' ";
$header = "";
$data = "";
$export = mysqli_query ($link, $qReport ) or die ( "Sql error : " . mysqli_error( ) );
$fields = mysqli_num_fields ( $export );
for ( $i = 0; $i < $fields; $i++ )
{
$header .= mysqli_fetch_fields( $export , $i ) . "t";
}
while( $row = mysqli_fetch_row( $export ) )
{
$line = '';
foreach( $row as $value )
{
if ( ( !isset( $value ) ) || ( $value == "" ) )
{
$value = "t";
}
else
{
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . "t";
}
$line .= $value;
}
$data .= trim( $line ) . "n";
}
$data = str_replace( "r" , "" , $data );
if ( $data == "" )
{
$data = "n(0) Records Found!n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$headern$data";
</code>
$filename = "Exportfullpo" . date('Y-m-d');
$qReport = " SELECT ID AS PurchaseOrder, date AS Date, time AS Time, employee AS Employee, vendor AS Vendor, jobsite AS Customer, description AS Description, price - (price * 0.047619) AS SUB, price * 0.047619 AS GST, price AS Price FROM purchase WHERE date >='$startdate' AND date <='$enddate' ";
$header = "";
$data = "";
$export = mysqli_query ($link, $qReport ) or die ( "Sql error : " . mysqli_error( ) );
$fields = mysqli_num_fields ( $export );
for ( $i = 0; $i < $fields; $i++ )
{
$header .= mysqli_fetch_fields( $export , $i ) . "t";
}
while( $row = mysqli_fetch_row( $export ) )
{
$line = '';
foreach( $row as $value )
{
if ( ( !isset( $value ) ) || ( $value == "" ) )
{
$value = "t";
}
else
{
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . "t";
}
$line .= $value;
}
$data .= trim( $line ) . "n";
}
$data = str_replace( "r" , "" , $data );
if ( $data == "" )
{
$data = "n(0) Records Found!n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$headern$data";
This issue also persists now on another form we use. So I’m thinking something in the server has changed to create this error?