Jump to content

write a text file fwrite()


kat35601

Recommended Posts

I need to write a text file using php below is my code but I get  errors

 

Warning: fwrite() expects parameter 1 to be resource, integer given in /var/www/html/dashboard/bs_kf_orders_file.php on line 34

Warning: fclose() expects parameter 1 to be resource, string given in /var/www/html/dashboard/bs_kf_orders_file.php on line 35

 

I think this my have something to do with permissions but I want to make sure I have the correct code.

<html>
<head>
</head>
<body>
<?php
$connect =odbc_connect("removed");
if(!$connect) {
	exit("Connection Failed: " . $connect);
}
$gr_total = 0;
 $gr_count =0;
$sql="removed";
$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
 while ($row = odbc_fetch_array($result))
{
  $gr_total = $gr_total + $row['total'];
   $gr_count = $gr_count + $row['uomptotalboxcount'];
 }
 $num2 = number_format( $gr_total, 2);
odbc_close($connect);

echo "$gr_count<br>";
echo "$num2";
    
$my_file = date('m-d-Y_hia').'.txt';
$handle = fopen($my_file, 'w+') or die('Cannot open file:  '.$my_file);
fwrite($gr_count,$num2);
fclose($my_file);
    
    
    
    
?>
</body>
</html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.