When I try running the script below, I get each of these two errors once for every row in my database. Can you please help me figure out what's wrong with my code? Thanks.
Warning: fwrite(): supplied argument is not a valid stream resource in /home/couponi/public_html/users/template.php on line 20
Warning: fclose(): supplied argument is not a valid stream resource in /home/couponi/public_html/users/template.php on line 21
<?php
$db = mysql_connect ("localhost", "database", "password");
mysql_select_db("databasename",$db);
$result = mysql_query("SELECT *
FROM `users`", $db);
while ($row = mysql_fetch_array($result)) {
$username= $row[username];
ob_start();
passthru("/home/files/public_html/users/ -source http://www.mysite.com/template.php?user=$username");
$html = ob_get_contents();
ob_end_clean();
// write output to file
$fp = fopen("$file", "w");
fwrite($fp, $html);
fclose($fp);
}
?>