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> Quote 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. Quote Link to comment Share on other sites More sharing options...
dalecosp Posted May 9, 2017 Share Posted May 9, 2017 (edited) 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. Edited May 9, 2017 by dalecosp Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.