S
(Shovel)
Guest
I'm learning... hence no mySQL on this site.
Also, because I don't have enough mySQL databases to give away to the guy I'm making this for.
In principal it's all going fine, but I'm getting an inexplicable error which I can't figure out, and searching google only gives me lots of sites that are suffering from the same error.. ahem.
Here's the entire block of code:
The problem occures in the "Write back to file" area. $nf, stands for "news file" and is an array of news entries, and $nf_ptr is the associated file pointer for the file on disk.
Oh, and "debug" is a little function that prints to screen, it's separated into a function so that I can disable the output when it goes live.
Anyway, here's what actually happens though:
The opens fine, and it gets created in the right directory, but it doesn't get written to. have also tried doing the file in the same directory as the PHP file and had the same lack of luck.
Earlier in the script, I wrote another bit of code, using a different file (in the same directory as the file) and that wrote fine. Therefore, I'm confused
Meep?
Also, because I don't have enough mySQL databases to give away to the guy I'm making this for.
In principal it's all going fine, but I'm getting an inexplicable error which I can't figure out, and searching google only gives me lots of sites that are suffering from the same error.. ahem.
Here's the entire block of code:
Code:
if($submit == "insert") {
/* Assemble File */
if(is_null($headline) || is_null($body)) { /* Check for null values */
echo("<h1>Error, you must enter a headline and body text</h1>");
break;
}
$news = array($date,
$username,
$headline,
htmlspecialchars($body));
$record = implode("|", $news);
$nf = file("../data/news");
/* Determine insert or update */
if($update == -1) {
/* Insert */
array_unshift($nf,$record);
debug("The news file now contains: $nf[0]");
}
else {
/* Update */
$nf[$update] = $record;
}
/* Write back to file */
$nf_ptr = fopen("../data/news",'w') || die("Could not open /data/news");
foreach ($nf as $line) {
fputs($nf_ptr, "$nf[0]\r\n");
debug("Writing $line\n");
}
fclose($nf_ptr);
}
The problem occures in the "Write back to file" area. $nf, stands for "news file" and is an array of news entries, and $nf_ptr is the associated file pointer for the file on disk.
Oh, and "debug" is a little function that prints to screen, it's separated into a function so that I can disable the output when it goes live.
Anyway, here's what actually happens though:
Code:
Warning: fputs(): supplied argument is not a valid stream resource in d:\bmpw\documents\webdev\local_http\control\gc.php on line 106
Writing 1055255181|/|Test News 1q|Hello!
Warning: fclose(): supplied argument is not a valid stream resource in d:\bmpw\documents\webdev\local_http\control\gc.php on line 109
The opens fine, and it gets created in the right directory, but it doesn't get written to. have also tried doing the file in the same directory as the PHP file and had the same lack of luck.
Earlier in the script, I wrote another bit of code, using a different file (in the same directory as the file) and that wrote fine. Therefore, I'm confused
Meep?