Jump to content

Recommended Posts

I have been trying to write multiple files at the same time and cannot seem to get it to write more than the first. It will write the first and go to write the second file, but then it stops and leaves the file blank. Im pulling variables from a form and having it write that value to a file, there are five total, but no matter what I do it will not write more than the first, help?


The "Change Colors" statement is the one with the five files that need to be written.

Here is where you can see the code...

[a href=\"http://nicotinejunkie.cv.vc/code.txt\" target=\"_blank\"]the code[/a]
Link to comment
https://forums.phpfreaks.com/topic/5084-writing-multiple-files/
Share on other sites

Wow, I can't believe that I missed that! But, even with those changes, there is no luck. And my host has errors turned off. but, I will put them back on and edit this post if there are any errors...

**EDIT: still no luck, there are no erros...**
Link to comment
https://forums.phpfreaks.com/topic/5084-writing-multiple-files/#findComment-18042
Share on other sites

[!--quoteo(post=355690:date=Mar 16 2006, 05:51 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 16 2006, 05:51 PM) [snapback]355690[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You still have syntax errors in this code. You have [code]<?php $fclose($two); ?>[/code] instead of [code]<?php fclose($two); ?>[/code].

Can you post the code to the script that drives this code?

Ken
[/quote]

I have fixed the $fclose to fclose, but still no luck, the two codes are here:
[a href=\"http://nicotinejunkie.cv.vc/code.txt\" target=\"_blank\"]Code 1[/a]
[a href=\"http://nicotinejunkie.cv.vc/code2.txt\" target=\"_blank\"]Code 2[/a]
Link to comment
https://forums.phpfreaks.com/topic/5084-writing-multiple-files/#findComment-18167
Share on other sites

Never ever hide errors. That is a very big mistake. Fix your errors because if all you do is hide them sure no one sees errors, but the code does not give the desired results either. Hiding notices is fine, but never hide errors. Even if your code still seems to work fine, when you post it to another server which still reports errors your users are going to see errors.
Link to comment
https://forums.phpfreaks.com/topic/5084-writing-multiple-files/#findComment-18171
Share on other sites

[!--quoteo(post=355735:date=Mar 16 2006, 08:14 PM:name=txmedic03)--][div class=\'quotetop\']QUOTE(txmedic03 @ Mar 16 2006, 08:14 PM) [snapback]355735[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Never ever hide errors. That is a very big mistake. Fix your errors because if all you do is hide them sure no one sees errors, but the code does not give the desired results either. Hiding notices is fine, but never hide errors. Even if your code still seems to work fine, when you post it to another server which still reports errors your users are going to see errors.
[/quote]

My host has errors turned off, in my code I have them turned with the ini_set, but no errors show...
Link to comment
https://forums.phpfreaks.com/topic/5084-writing-multiple-files/#findComment-18177
Share on other sites

You had a lot of redundant code...I think I eliminated most of it.

You also still had a few $ infront of fwrite and fclose fuctions. I've used servers before that will not show any syntax errors at all, even if error reporting is on and turned to E_ALL. It's irritating, to say the least.

Hope this helps, make sure to remove the spaces in all the file functions...the forum software doesn't like those functions.

[code]<?php

$logfile = "log/log.txt";
$log = file_get_contents($logfile);
$date = date('l, F d, Y (g:ia)');
$ip = $_SERVER['REMOTE_ADDR'];

$user = $_POST['user'];
$pass = $_POST['pass'];
$action = $_POST['action'];
$filename = "usercomments/usercomments.php";
$filenametwo = "usercomments/lock.php";

$filetopcolor = "usercomments/topcolor.php";
$writetopcolor = $_POST['topbg'];

$filebottomcolor = "usercomments/bottomcolor.php";
$writebottomcolor = $_POST['bottombg'];

$filetopfont = "usercomments/topfont.php";
$writetopfont = $_POST['topfont'];

$filebottomfont = "usercomments/bottomfont.php";
$writebottomfont = $_POST['bottomfont'];

$fileborder = "usercomments/border.php";
$writeborder = $_POST['border'];

$write = "There are no comments.<br>";
$writetwo = "1";
$writethree = "0";

ini_set("display_errors", "1");
ini_set("error_reporting", "E_ALL");

if ($_POST[user] == "user") {
    if ($_POST[pass] == "pass") {

        if ($action == "Clear Comments") {
            $f ileopen = f open($filename, 'w') or die("Can't open file.");
            f write($fileopen, $write);
            $message = "The comments have been cleared.<br><br>";
            $logwrite = ("Comments cleared by: " . $ip . " || " . $date);
            f close($fileopen);
            
        } else if ($action == "Lock Comments") {
            $fileopen = f open($filenametwo, 'w') or die("Can't open file.");
            f write($fileopen, $writetwo);
            $message = "The comments have been locked. <img src=images/clock2.png></img><br><br>";
            $logwrite = ("Comments locked by: " . $ip . " || " . $date);
            f close($fileopen);
            
        } else if ($action == "Unlock Comments") {
            $fileopen = f open($filenametwo, 'w') or die("Can't open file.");
            f write($fileopen, $writethree);
            $message = "The comments have been unlocked. <img src=images/clock.png></img><br><br>";
            $logwrite = ("Comments unlocked by: " . $ip . " || " . $date);
            f close($fileopen);
            
        } elseif ($action == "Change Colors") {
            if ($writetopfont == null) {
                $message .= "No changes to $filetopfont<br>";
                $numberone++;
            } else {
                $fileopen = f open($filetopfont, 'w') or die("Cant open Top Font.");
                f write($fileopen, $writetopfont);
                $message .= "$filetopfont has been changed to $writetopfont<br>";
                f close($fileopen);
                $numberone++;
            }
            
            if ($writetopcolor == null) {
                $message .= "No changes to $filetopcolor<br>";
                $numbertwo++;
            } else {
                $two = f open($filetopcolor, 'w') or die("Cant open Top Color.");
                f write($two, $writetopcolor);
                $message .= "$filetopcolor has been changed to $writetopcolor<br>";
                f close($two);
                $numbertwo++;
            }
            
            if ($writebottomfont == null) {
                $message .= "No changes to $filebottomfont<br>";
                $numberthree++;
            } else {
                $three = f open($filebottomfont, 'w') or die("Cant open Bottom Font.");
                f write($three, $writebottomfont);
                $message .= "$filebottomfont has been changed to $writebottomfont<br>";
                f close($three);
                $numberthree++;
            }
            
            if ($writebottomcolor == null) {
                $message .= "No changes to $filebottomcolor<br>";
                $numberfour++;
            } else {
                $four = f open($filebottomcolor, 'w') or die("Cant open Bottom Color.");
                f write($four, $writebottomcolor);
                $message .= "$filebottomcolor has been changed to $writebottomcolor<br>";
                f close($four);
                $numberfour++;
            }
            
            if ($writeborder == null) {
                $message .= "No changes to $fileborder<br>";
                $numberfive++;
            } else {
                $five = f open($fileborder, 'w') or die("Cant open Border.");
                f write($five, $writeborder);
                $message .= "$fileborder has been changed to $writeborder<br>";
                close($five);
                $numberfive++;
            }
        }
    } else {
        echo "Invalid Password.";
    }
} else {
    echo "Invalid Username.";
}

//log write code
if ($logwrite != "") {
    $logwrite = "<table border=0 width=100%><tr><td vAlign=top align=left>-</td><td vAlign=top align=left>" . $logwrite . "</td></tr></table>";
    if ($log == "No log entries.") {
        $two = f open($logfile, 'w') or die("Cant open log.");
        f write($two, $logwrite);
        f close($two);
    } else {
        $two = f open($logfile, 'w') or die("Cant open log.");
        f write($two, $logwrite);
        f close($two);
    }
}

echo $message . "<a href=ap.php>Back to Admin Panel</a>";

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/5084-writing-multiple-files/#findComment-18209
Share on other sites

My code works fine once you pull all of the "$" out of the file commands. Thanks for your help! I guess I was so frustrated that I couldnt get it to work, that I skipped over that all together, twice! Thank you so so much. I have been trying to get that to work for over a week....and phpfreaks wouldnt let me post >_< ...Thanks alot guys!
Link to comment
https://forums.phpfreaks.com/topic/5084-writing-multiple-files/#findComment-18257
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.