kat35601 Posted May 9, 2017 Share Posted May 9, 2017 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 34Warning: 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 More sharing options...
ginerjm Posted May 9, 2017 Share Posted May 9, 2017 Have you read the manual for fwrite()? It would give you some GREAT examples of how you using this function incorrectly. Link to comment Share on other sites More sharing options...
dalecosp Posted May 9, 2017 Share Posted May 9, 2017 fwrite() expects a valid file handle ('resource') ...If possible, I'd recommend file_put_contents() instead ... it avoids most of the complexity of the lower-level file writing operations. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.