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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.